Main Index |
Top Of Tree |
Tag Index |
Tag History
[NOTICE: It has
become patently obvious to me that I still do not know enough about scripting -
both JavaScript and VBScript - to write an adequate page to even scratch the
surface of the capabilities of these engines, even to the extent of how they
interface with HTML. I will try to remedy this, but in the meantime please
consult the Related Links for pointers to sites
that cover this topic in much greater depth. Thanks, -ed.]
- What is it?
- The Script tag is the method used by browsers to recognize
scripting languages in an HTML document. Scripting allows web pages to
change dynamically in response to events such as screen exit and entry,
or user mouse-clicks . The most popular browser scripting languages
currently are JavaScript and VBScript. 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.
Scripts can exist either embedded within a document or may be located
elsewhere. If the script code is contained within a web page, it will be
embedded within an HTML comment between the Script container tags
(nesting within a comment is important in order to make the script invisible
to browsers that do not support the feature.) Statements are evaluated
when the document is loaded. If a Script attempts to reference document
objects defined by HTML elements occurring later in the document, the
attempt will fail. Because of this, it is generally safest to place a
SCRIPT statement at the top of a document in the HEAD element.
NOTE: Scripts can also be invoked
using the A element combined with Script
code in place of the destination URL. This allows a script (either inline
or located in a SCRIPT element) to be executed when the user clicks on
a hyperlink.
- Syntax: [script-engine]:[script-code]
- Where [script-engine] is the name of the scripting language used,
and [script-code] is either in-line script code or script code referenced
elsewhere in the document.
- Example: (displays an alert message box that
contains the text 'hi there')
- <a
HREF="JavaScript:alert('hi
there')">Click me to see a message.</a>
- Attributes
- Language
- 2 | 3
| 3.2 | IE3B1
| M | N2B3
- 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 | IE
| M | N3B5
- Required? No
- Description:
This attribute specifies an external source for the script code.
- Values: An absolute or relative URL
- Event Handlers
- By adding some new attributes to HTML tags, a SCRIPT can be linked to
a dynamic document action. These attributes are known as "Event
Handlers" and they serve to catch document events and trigger Script
code. The A, BODY, FORM, and INPUT tags all use at least one of these
attributes.
- onBlur
- Attribute of: ilayer,
layer, select,
text, textarea
- Example: <input
TYPE="text"
NAME="userName"
onBlur="required(this.value)">
- Description:
A blur Event Handler executes Script code when a form field or layer loses focus.
onChange
- Attribute of: select,
text, textarea
- Example: <input
TYPE="text"
NAME="userName"
onChange="checkValue(this.value)">
- Description:
A change Event Handler executes Script code when a form field loses focus and its
value has been modified. This Event Handler is used to validate data after it is
modified by a user.
onClick
- Attribute of: button,
checkbox, radio,
hyperlink, reset,
submit
- Example: <a
HREF=""
NAME="userName"
onClick="this.href=pickRandomURL()">
- Description:
A click Event Handler executes Script code when an object is clicked.
onFocus
- Attribute of: ilayer,
layer, select,
text, textarea
- Example: <input
TYPE="textarea"
NAME="valuefield"
onFocus="valueCheck()">
- Description:
A focus Event Handler executes Script code when a form field or layer receives
input focus by tabbing with the keyboard or clicking with the mouse. Important:
Selecting within a form field results in a onSelect event, not a onFocus event.
onLoad
- Attribute of: body,
frameset, ilayer,
layer
- Example: <body
onLoad="window.alert('Welcome
to the Brave New World home page!')">
- Description:
This attribute executes Script code with the completion of loading of a window,
layer, or when all frames within a Frameset have finished loading. In a Frame
document scenario, an onLoad event in the BODY tag of a sub-frame will occur
before an onLoad event within the parent FRAMESET tag.
onMouseOver
- Attribute of: hyperlink,
ilayer, layer,
- Example: <a
HREF="URL"
NAME="userName"
onMouseOver="window.status='Click this
if you dare!'; return true">
- Description:
A mouseOver Event Handler executes Script code once each time the mouse pointer
enters the bounds of an object from outside the object.
onMouseOut
- Attribute of: hyperlink,
ilayer, layer,
- Example: <a
HREF="URL"
NAME="userName"
onMouseOut="window.status='Click this
if you dare!'; return true">
- Description:
A mouseOout Event Handler executes Script code once each time the mouse pointer
exits the bounds of an object from inside the object.
onSelect
- Attribute of: text,
textarea
- Example: <input
TYPE="text"
NAME="valueField"
onSelect="selectState()">
- Description:
A select Event Handler executes Script code when a user selects some of the text within a form field.
onSubmit
- Attribute of: form
- Example: <form
onSubmit="return formData(this)">
- Description:
A submit Event Handler executes Script code when a user submits a form. It can also be
used to prevent a form from being submitted; to do so, put a return statement that returns
false in the event handler. Any other returned value lets the form submit. If you omit the
return statement, the form is submitted.
onUnload
- Attribute of: body,
frameset
- Example:<body
onUnload="cleanUp()">
- Description:
An unLoad Event Handler executes Script code when the user exits a document. In a Frame
document scenario, an onUnload event in the BODY tag of a sub-frame will occur before an
onUnload event within the parent FRAMESET tag.
- 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
-
%Anchors% |
%Virtual
Formatting% |
%Physical
Formatting% |
%Block Format
Parent% |
%Multimedia
Parent% |
<Body> |
<Head> |
<Address> |
<Basefont> |
<Heading> |
<Marquee>
- Content Model
- %Text%
Tips & Tricks
- DTD Note: The Internet Explorer 3.0
DTD lists extra supported attributes for script: NAME and TYPE.
I have not yet verified if these are really supported yet in IE3.
Browser Peculiarities
Boring Copyright Stuff...