Javascript is a compact, object-based scripting language. It can provide interactive web pages, validate form data, and make your web page clearer.
<SCRIPT>
JavaScript code goes here...
</SCRIPT>
You can optionally specify the LANGUAGE attribute in the SCRIPT tag.
<SCRIPT LANGUAGE="JavaScript">
JavaScript code goes here...
</SCRIPT>
For older browsers which do not understand JavaScript, you need to hide
the script with the comment tags.
<SCRIPT LANGUAGE="JavaScript">
<!-- hide JavaScript from older browsers
JavaScript code goes here...
// end hiding from older browsers -->
</SCRIPT>
If you wish to define functions, they should be defined in the HEAD
part of the HTML document. This is because the HEAD is the first
part of the document which is loaded, and that ensures that your functions
will be available for your JavaScript code.
A complete HTML example document:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- hide JavaScript from older browsers
function bar() {
document.write("Hi there.")
}
// end hiding from older browsers -->
</SCRIPT>
</HEAD>
<BODY>
HTML document goes here...
</BODY>
</HTML>
And last, but certainly not least, you may put JavaScript statements within
HTML tags. For example, an event handler is placed directly in the tag:
<input type="button" onClick="foo()">If you don't understand what the onClick event is, don't worry. We'll be getting to that later. You can also place it on the right side of a name/value pair. For example:
<input type="text" value="compute_value()">In this example, the value returned by the function compute_value is returned and is used for the value of the INPUT tag.