JavaScript, The Very Basics

JavaScript (Jscript) is contained between <SCRIPT> and </SCRIPT> tags. The opening tag should look like this:

<SCRIPT language="JavaScript">

The language="JavaScript" is there to tell the browser that the code is in JavaScript and not some other language like VBscript. The javascript comes next followed by a closing </SCRIPT> tag:

<SCRIPT language="JavaScript">

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

</SCRIPT>

You may have as many <SCRIPT> tags as you wish. Just be sure to end the script with the </SCRIPT> tag. If you plan to use javascript functions you must place these inside the <HEAD> and <HEAD> tags like this:

<HEAD>
<TITLE>My Page</TITLE>

<SCRIPT language="JavaScript">

function stuff()
{
JavaScript code...
}

</SCRIPT>

</HEAD>

One last thing. Older browsers do not always support javascript. They will do bad things when they see it (normally just display it as text, but not always). To hide it from them you need to enclose the script inside of comment tags like this:

<SCRIPT language="JavaScript">

<!-- This starts the HTML comments that will hide the script from old browsers

.....Javascript Statements.....

//--> This ends the comment section and the browser will read on normally again.

</SCRIPT>

Thats it for the basics!

Back to Index    Retrun to Home Page