Webmaster Resources Center

Welcome to the Bravenet Resource Center. Use these resources to help make your web pages more advanced and fun to use.

Quick Reference Sheets for Webmasters

Quick Reference sheets are packed full of useful information for all webmasters.

HTML Reference Sheet

Using Scripts

A client-side script is a program that may accompany an HTML document or be embedded directly in it. The program executes on the client's machine when the document loads, or at some other time such as when a link is activated. HTML's support for scripts is independent of the scripting language.

Scripts offer authors a means to extend HTML documents in highly active and interactive ways. For example:

  • Scripts may be evaluated as a document loads to modify the contents of the document dynamically.
  • Scripts may accompany a form to process input as it is entered. Designers may dynamically fill out parts of a form based on the value of other fields. They may also ensure that input data conforms to predetermined ranges of values, that fields are mutually consistent, etc.
  • Scripts may be trigerred by events that affect the document, such as loading, unloading, element focus, mouse movement, etc.
  • Scripts may be linked to form controls to produce user interface elements.

There are two types of scripts authors may attach to an HTML document:

  • Those that are executed one time when the document is loaded by the user agent. Scripts that appear within a script element are executed when the document is loaded. For browsers that cannot or will not handle scripts, authors may include alternate content via the noscript element.
  • Those that are executed every time a specific event occurs. These scripts may be assigned to a number of elements via the intrinsic event attributes.

The SCRIPT element

The SCRIPT element places a script within a document. This element may appear any number of times in the HEAD or BODY of an HTML document. script may be defined within the contents of the SCRIPT element or in an external file. If the src attribute is not set, user agents must interpret the contents of the element as the script. If the src has a URI value, user agents must ignore the element's contents and retrieve the script via the URI. Note that the charset attribute refers to the character encoding of the script designated by the src attribute; it does not concern the content of the SCRIPT element.

The follow example details how you could use javascript to change the contents of a DIV dynamically:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<title>Change the contents of the DIV tag</title>
<script type="text/javascript">
document.getElementById('divText').innerHTML = 'Hi mom!';
<div id="divText">
Hello world!

In the above sample, the text "Hello world!" is replace with the text "Hi mom!" by javascript dynamically. For more information about javascript, check out the Javascript Articles from the articles section.