MF Web Services logo

HTML Help & Resources

Document Scripting

All scripting definitions must have a starting and ending tag. Omitting either will have erratic results. Even if the source of your script is external, contained in another file, you still must end the scripting tag, despite there might not be any code inserted between the tags. There are three methods in which you can deploy scripting elements. They are listed below.

LANGUAGE defines which language, and optionally, what version of the language is being used. In almost all cases, Javascript is the language used because of its client-side capabilities allowing the manipulation of data and documents after the page has been loaded from an external server. In this example we use Javascript version 1.2.

The elements of scripting, namely Javascript, and how to use it, are not covered in this reference. For more information on how to utilize the power of scripting and Javascript, visit our Javascript reference instead.

Method #1 - Inside the Document Head

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
  <HEAD>
    <TITLE>My First HTML Document</TITLE>
    ... META DATA ...
    <SCRIPT TYPE="text/javascript" SRC="scriptname.js"></SCRIPT>
  </HEAD>
  <BODY>
  <P>This is my first HTML document.</P>
  
  <P>Sending you to my second HTML document...</P>
  
  
  <P>If this page does not refresh in 10 seconds, go to second HTML document .</P>
  </BODY>
</HTML>

An important consideration is where in the document the script is loaded. Everything in the document head is loaded and accessed first, so values, but not elements, defined inside the document body will be invisible initially.

Method #2 - Inside the Document Body - External File

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
  <HEAD>
    <TITLE>My First HTML Document</TITLE>
    ... META DATA ...
  </HEAD>
  <BODY>
  <P>This is my first HTML document.</P>
  
  <SCRIPT TYPE="text/javascript" SRC="scriptname.js"></SCRIPT>
  <P>Sending you to my second HTML document...</P>
  
  
  <P>If this page does not refresh in 10 seconds, go to second HTML document .</P>
  </BODY>
</HTML>

The deployment of this script differs only by the loaded location, inside the document body. However, the same rules apply, as in the above example - any values defined after where the script is loaded are invisible to the script initially.

Method #3 - Inside the Document Body - Script Text

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
  <HEAD>
    <TITLE>My First HTML Document</TITLE>
    ... META DATA ...
  </HEAD>
  <BODY>
  <P>This is my first HTML document.</P>
  
  <SCRIPT TYPE="text/javascript">
  document.write('my script');
  </SCRIPT>
  <P>Sending you to my second HTML document...</P>
  
  
  <P>If this page does not refresh in 10 seconds, go to second HTML document .</P>
  </BODY>
</HTML>

In this example, the scripting is not external, but defined inside the document. Again, where the script is placed determines what values, if any, the script can access, just as in the previous two examples.

Move on to the Next Topic - Document No Scripting.