Lesson-1 (Javascript Introduction)

To get started with JavaScript, you will want to be able to 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 appear like this:

<SCRIPT language="JavaScript">

The language="JavaScript" command is there so the browser can tell the code that follows is in JavaScript and not another scripting language, such as VBScript. The javascript code will follow this tag, and end with the </SCRIPT> tag:

<SCRIPT language="JavaScript">

........JavaScript Code...........

</SCRIPT>

You can have as many <SCRIPT> tags as you need throughout the body of your HTML document, just as though it were a normal tag. Just remember to close each tag before you go on! Also, if you are going to use JavaScript functions (we will get to these later on) , you will need to place your functions inside the <HEAD> </HEAD> tags of your document. This way, your functions are loaded before the page begins to display, and you won't see all kinds of JavaScript errors. Here is an example:

<HEAD>
<TITLE>My World</TITLE>

<SCRIPT language="JavaScript">

function cool()
{
JavaScript Stuff...
}

</SCRIPT>

</HEAD>

Now, there is still one last thing you should see before we begin writing scripts. Since there are older browsers being used out there, 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 have to trick the browser into ignoring the text within the <SCRIPT> tag. This is done by using an HTML comment. The older browsers will ignore the text inside the comments, but a JavaScript capable browser 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>