The opening tag is usually like this: <SCRIPT language="JavaScript">
The language="JavaScript" command is there so the browser can recognize that the code that is following is in JavaScript and not another scripting language, ex.: Visual Basic Script. VBScript. |
<SCRIPT language="JavaScript">
// -- JavaScript Code --
</SCRIPT> |
There is no limit in the number of scripts that an HTML page can contain. Don't forget to always close your tags before continuing. Functions inside the <HEAD> </HEAD>tags of your document are JavaScript functions (we'll get to this in the next tutorials). We always put these functions between the <HEAD> </HEAD> tags, this way your functions are loaded before the page begins to display, and you won't see all kinds of JavaScript errors.
|
<HEAD>
<TITLE>Your Title</TITLE>
<SCRIPT language="JavaScript">
function xxxxx()
{
JavaScript Stuff... a
}
</SCRIPT>
</HEAD |
Before we begin writing scripts, we need to do something first. Old browsers are unable to read the <SCRIPT> tags. Instead of executing the JavaScript, they will display just the text. To solve this problem, we have to trick the browser into ignoring the text between the <SCRIPT> tags. HTML comments will be used, the older browsers will ignore the text inside the comments, but a JavaScript capable browsers will go ahead and perform your script. Here is how to do it: |
<SCRIPT language="JavaScript">
<!-- This opens the HTML comments that will hide the script from old browsers
......JavaScript Statements.......
//--> This closes the comment section and the browser will read on normally
</SCRIPT> |