Below you see the tag that will set a script apart from the HTML. The tags used to begin and end a script are the <SCRIPT> and </SCRIPT> tags. The opening tag should look like this:
<SCRIPT language="JavaScript">
The language="JavaScript" command is there so that the browser can tell the code that follows is
in JavaScript and not another scripting language. After this tag javascript code
will follow, and end with the </SCRIPT> tag:
<SCRIPT language="JavaScript">
......Your JavaScript Code...........
</SCRIPT>
You can have as many <SCRIPT> tags as you need throughout the body of your HTML document,
as though it were a normal tag, just remember to close each tag before you go on to the next!
If you need your functions to be loaded before the page begins to display then place your
functions inside the <HEAD> </HEAD> , but it may also be the other way around, that
you need some layers to be loaded before the javascript starts then you can place it inside
<BODY> </BODY> tags. Another way is to use the onLoad=function(); inside the
<BODY> tag.
<HEAD>
<TITLE>Your title</TITLE>
<SCRIPT language="JavaScript">
function cool()
{
Some JavaScript...
}
</SCRIPT>
</HEAD>
Now, there is still one last thing you should see before we begin writing scripts. There
are older browsers being used and they do not recognize the <SCRIPT> tag. Rather
than performing your javascript, they will display the text of your script as though you meant
for it to be a few lines of text on the screen. To get around this problem, you must trick the
browser into ignoring the text within the <SCRIPT> tag. You do this by using an HTML
comment. The JavaScript capable browser will go ahead and perform your script, but the
older browsers will ignore the text inside the comments. This is how to write 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>
<< BACK - NEXT >>