Script

End Tag: Required
Support Key: 2 | 3 | 3.2*| 4 | IE3B1 | M | N2B3 | O3
What is it?
Attributes
Tag Example
Parent/Content Model
Tips & Tricks
Browser Peculiarities
= Index DOT Html by Brian Wilson [bloo@blooberry.com] =
Main Index | Element Tree | Element Index | HTML Support History


What is it?
The SCRIPT element is the method used by browsers to recognize scripting languages in an HTML document. Scripting (both embedded and external to the page) allows web pages to perform actions and change dynamically in response to events such as screen exit and entry, or user mouse-clicks.

While discussing the full scope of scripting in HTML pages is not the intent of these documents, discussion of how scripting affects HTML authoring is DEFINITELY relevant. Many other sites have covered the details with far greater skill and detail than I could ever manage. Please see the Related Links section for pointers to good resources on the subject.
JavaScript and Other Scripting Languages
The most popular browser scripting language at this time is the JavaScript language from Netscape. The JavaScript language has been standardized by ECMA as ECMA-262, (AKA EcmaScript.) Microsoft has also implemented a version of the JavaScript language under the name JScript.

While JavaScript is the most widely implemented scripting language, it is possible to use any language, provided the browser you are using can understand it. Microsoft, for example, also makes a scripting language for the Internet Explorer browser called VBScript (based on the Visual Basic programming language) and a few other languages (such as Perl) are also usable with some web browsers.
Event Handlers and Script Invocation
Scripting code can be invoked either as a function call to a routine contained in the SCRIPT element or the scripting language statements can be included in-line within the attribute value of the attribute that invokes it.

To allow scripting to interact dynamically with web page elements, a new class of HTML attribute has been added called "Event Handlers." These HTML attributes (there are now over 50 different events) trigger script code when the action/event that they are bound to occurs for an element.

Javascript allows an extra type of event trapping beyond event handlers. The A HREF element can also be used to invoke script code. The script is run when the user activates the hyperlink (see the A HREF page for more details.)

Common Attributes
%Core%
2 | 3 | 3.2 | 4 | IE4 | M | N | O

Specific Attributes
Charset
2 | 3 | 3.2 | 4 | IE | M | N | O
Required? No
Description:
This indicates the character encoding of the script contents.
Values:
A recognized RFC 2045 language character set string. Default is ISO-8859-1.
Defer
2 | 3 | 3.2 | 4 | IE4 | M | N | O
Required? No
Description:
This stand alone attribute is used to advise the browser that the script is not going to generate any rendered document content and thus, the user agent can continue parsing and rendering.
Values: NA
Event
2 | 3 | 3.2 | 4 | IE4 | M | N | O
Required? No
Description:
Specifies the event the script is being written for.
Values: Event name
For
2 | 3 | 3.2 | 4 | IE4 | M | N | O
Required? No
Description:
Specifies which element is being bound to the event script.
Values: A scripting object or element ID.
Language
2 | 3 | 3.2 | 4 | IE3B1 | M | N2B3 | O3
Required? No
Description:
This attribute indicates the scripting language the script is written in. It is required if the SRC attribute is not specified, optional otherwise.
Values:
The two most popular scripting languages currently are JavaScript and VBScript.
Src
2 | 3 | 3.2 | 4 | IE3.01 | M | N3B5 | O3
Required? No
Description:
This attribute specifies an external source for the script code.
Values: An absolute or relative URL
Type
2 | 3 | 3.2 | 4 | IE4 | M | N?? | O
Required? No
Description:
This attribute specifies the MIME type of the scripting code.
Values: Alphanumeric MIME type
Example
<html>
<head>
   <script LANGUAGE="JavaScript">
      <!-- hide script from old browsers
      function getname(str) {
      alert("Hi, "+ str+"!");
      }
      // end hiding contents -->
   </script>
</head>
<body>
   Please enter your name:
   <form>
      <input TYPE="text" NAME="name" onBlur="getname(this.value)" VALUE="">
   </form>
</body>
</html>
Parent Model
%In-line Parent% | %Block Parent% | <Head>
Content Model
%Text% | <!-- -->
Tips & Tricks Browser Peculiarities
Boring Copyright Stuff...