Intro to JavaScript - continued

Session 10 | Main Page | Previous Page | Next Page


Script Tags

Script tags use the following syntax: <SCRIPT LANGUAGE="JavaScript|Jscript|VBScript"> <!-- code goes here! // --> </SCRIPT>


The script code may be placed almost anywhere in the document, but should be positioned such that it is interpreted before it is accessed. For example, if a JavaScript function is called from the BODY tag, the function should be defined ahead of the BODY tag so the browser knows it exists before it tries to call it. In some cases, the script needs to be placed in a specific location. Multiple SCRIPT tag sets are allowed inside a single document.

Remember that all JavaScript code is case sensitive!

Your First Script

Comments may be placed inside the JavaScript using either:

// - double slashes at the beginning of each line or /* */ - these characters surrounding one or more lines of comments

The syntax for JavaScript object references follows the standard dot structure:

object.[property].[method][(arguments);

Brace brackets are used to enclose blocks of related code, such as functions.

To write a line of text onto a page, use the "write" method associated with the the document object as follows:

<SCRIPT LANGUAGE="JavaScript"> <!-- document.write("Bill Cassidy"); // --> </SCRIPT>

This script must be placed at the location where the text is to be written, as shown below.


HTML may also be included in the text string to provide formatting of the output on the web page as follows:

<SCRIPT LANGUAGE="JavaScript"> <!-- document.write("<P><B>Bill Cassidy</B>"); // --> </SCRIPT>


Session 10 | Main Page | Previous Page | Next Page