HTML 4.01 Test Suite - Assertions
Testable Assertions: Section 18 Scripts
18 Scripts - Animated Documents and Smart Forms
Assertion 18.1-1
(may) 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.
Tests: None
Assertion 18.1-3
(author)(may) There are two types of scripts authors may attach to an HTML document:
1. 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 user agents that cannot or will not handle scripts, authors may include alternate content via the NOSCRIPT element.
2. 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.
Tests: None
Assertion 18.2.1-1
(author)(must) Start tags and End tags for script elements are required.
Tests: None
Assertion 18.2.1-2
(must) SCRIPT: src = uri [CT]
This attribute specifies the location of an external script.
Assertion 18.2.1-3
(must) SCRIPT: type = content-type [CI]
This attribute specifies the scripting language of the element's contents and overrides the default scripting language. The scripting language is specified as a content type (e.g., "text/javascript").
Assertion 18.2.1-4
(author)(must) Authors must supply a value for this attribute (SCRIPT: type = content-type [CI]).. There is no default value for this attribute.
Tests: None
Assertion 18.2.1-5
(must)(deprecated) SCRIPT: language = cdata [CI]
Deprecated. This attribute specifies the scripting language of the contents of this element. Its value is an identifier for the language, but since these identifiers are not standard, this attribute has been deprecated in favor of type.
Tests: None
Assertion 18.2.1-6
(must) SCRIPT: defer [CI]
When set, this boolean attribute provides a hint to the user agent that the script is not going to generate any document content (e.g., no "document.write" in javascript) and thus, the user agent can continue parsing and rendering.
Assertion 18.2.1-7
(must) 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.
Tests: None
Assertion 18.2.1-8
(may) The script may be defined within the contents of the SCRIPT element or in an external file.
Tests: None
Assertion 18.2.1-9
(must) If the src attribute is not set, user agents must interpret the contents of the element as the script.
Assertion 18.2.1-10
(must) If the src has a URI value, user agents must ignore the element's contents and retrieve the script via the URI.
Assertion 18.2.1-12
(must) Scripts are evaluated by script engines that must be known to a user agent.
Tests: None
Assertion 18.2.1-13
(should) The syntax of script data depends on the scripting language.
Tests: None
Assertion 18.2.2-1
(author)(must) As HTML does not rely on a specific scripting language, document authors must explicitly tell user agents the language of each script.
Tests: None
Assertion 18.2.2-2
(must) Specifying the scripting language may be done either through a default declaration or a local declaration.
Tests: None
Assertion 18.2.2-3
(author)(should) Authors should specify the default scripting language for all scripts in a document by including the META declaration in the HEAD.
Tests: None
Assertion 18.2.2-4
(should) In the absence of a META declaration, the default can be set by a "Content-Script-Type" HTTP header.
Tests: None
Assertion 18.2.2-5
(should) User agents should determine the default scripting language for a document according to the following steps (highest to lowest priority):
1. If any META declarations specify the "Content-Script-Type", the last one in the character stream determines the default scripting language.
2. Otherwise, if any HTTP headers specify the "Content-Script-Type", the last one in the character stream determines the default scripting language.
Tests: None
Assertion 18.2.2-6
(author)(must) Documents that do not specify default scripting language information and that contain elements that specify an intrinsic event script are incorrect.
Tests: None
Assertion 18.2.2-7
(may) User agents may still attempt to interpret incorrectly specified scripts but are not required to.
Tests: None
Assertion 18.2.2-8
(author)(should) Authoring tools should generate default scripting language information to help authors avoid creating incorrect documents.
Tests: None
Assertion 18.2.2-9
(author)(must) The type attribute must be specified for each SCRIPT element instance in a document.
Tests: None
Assertion 18.2.2-9
(must) The value of the type attribute for a SCRIPT element overrides the default scripting language for that element.
Tests: None
Assertion 18.2.2-11
(should) Scripts should refer to an element according to its assigned name. Scripting engines should observe the precedence rules (described in 18.2.3)when identifying an element: a name attribute takes precedence over an id if both are set. Otherwise, one or the other may be used.
Tests: None
Assertion 18.2.3-2
(must) Intrinsic events: onload = script [CT]
The onload event occurs when the user agent finishes loading a window or all frames within a FRAMESET.
Assertion 18.2.3-3
(must) Intrinsic events: onload = script [CT]
This attribute may be used with BODY and FRAMESET elements.
Tests: None
Assertion 18.2.3-4
(must) Intrinsic events: onunload = script [CT]
The onunload event occurs when the user agent removes a document from a window or frame.
Assertion 18.2.3-5
(must) Intrinsic events: onunload = script [CT]
This attribute may be used with BODY and FRAMESET elements.
Tests: None
Assertion 18.2.3-6
(must) Intrinsic events: onclick = script [CT]
The onclick event occurs when the pointing device button is clicked over an element.
Tests: None
Assertion 18.2.3-7
(must) Intrinsic events: onclick = script [CT]
This attribute may be used with most elements.
Tests: None
Assertion 18.2.3-8
(must) Intrinsic events: ondblclick = script [CT]
The ondblclick event occurs when the pointing device button is double clicked over an element.
Assertion 18.2.3-9
(must) Intrinsic events: ondblclick = script [CT] (This attribute may be used with most elements.
Tests: None
Assertion 18.2.3-10
(must) Intrinsic events: onmousedown = script [CT]
The onmousedown event occurs when the pointing device button is pressed over an element.
Assertion 18.2.3-11
(must) Intrinsic events: onmousedown = script [CT]
This attribute may be used with most elements.
Tests: None
Assertion 18.2.3-12
(must) Intrinsic events: onmouseup = script [CT]
The onmouseup event occurs when the pointing device button is released over an element.
Assertion 18.2.3-13
(must) Intrinsic events: onmouseup = script [CT]
This attribute may be used with most elements.
Tests: None
Assertion 18.2.3-14
(must) Intrinsic events: onmouseover = script [CT]
The onmouseover event occurs when the pointing device is moved onto an element.
Assertion 18.2.3-15
(must) Intrinsic events: onmouseover = script [CT]
This attribute may be used with most elements.
Tests: None
Assertion 18.2.3-16
(must) Intrinsic events: onmousemove = script [CT]
The onmousemove event occurs when the pointing device is moved while it is over an element.
Assertion 18.2.3-17
(must) Intrinsic events: onmousemove = script [CT]This attribute may be used with most elements.
Tests: None
Assertion 18.2.3-18
(must) Intrinsic events: onmouseout = script [CT]
The onmouseout event occurs when the pointing device is moved away from an element.
Assertion 18.2.3-19
(must) Intrinsic events: onmouseout = script [CT]
This attribute may be used with most elements.
Tests: None
Assertion 18.2.3-20
(must) Intrinsic events: onfocus = script [CT]
The onfocus event occurs when an element receives focus either by the pointing device or by tabbing navigation.
Assertion 18.2.3-21
(must) Intrinsic events: onfocus = script [CT]
This attribute may be used with the following elements: A, AREA, LABEL, INPUT, SELECT, TEXTAREA, and BUTTON.
Tests: None
Assertion 18.2.3-22
(must) Intrinsic events: onblur = script [CT]
The onblur event occurs when an element loses focus either by the pointing device or by tabbing navigation.
Assertion 18.2.3-23
(must) Intrinsic events: onblur = script [CT]
This attribute may be used with the same elements as onfocus.
Tests: None
Assertion 18.2.3-24
(must) Intrinsic events: onkeypress = script [CT]
The onkeypress event occurs when a key is pressed and released over an element.
Assertion 18.2.3-25
(must) Intrinsic events: onkeypress = script [CT]
This attribute may be used with most elements.
Tests: None
Assertion 18.2.3-26
(must) Intrinsic events: onkeydown = script [CT]
The onkeydown event occurs when a key is pressed down over an element.
Assertion 18.2.3-27
(must) Intrinsic events: onkeydown = script [CT]
This attribute may be used with most elements.
Tests: None
Assertion 18.2.3-28
(must) Intrinsic events: onkeyup = script [CT]
The onkeyup event occurs when a key is released over an element.
Assertion 18.2.3-29
(must) Intrinsic events: onkeyup = script [CT]
This attribute may be used with most elements.
Tests: None
Assertion 18.2.3-30
(must) Intrinsic events: onsubmit = script [CT]
The onsubmit event occurs when a form is submitted.
Assertion 18.2.3-31
(must) Intrinsic events: onsubmit = script [CT]
It only applies to the FORM element.
Tests: None
Assertion 18.2.3-32
(must) Intrinsic events: onreset = script [CT]
The onreset event occurs when a form is reset.
Assertion 18.2.3-33
(must) Intrinsic events: onreset = script [CT]
It only applies to the FORM element.
Tests: None
Assertion 18.2.3-34
(must) Intrinsic events: onselect = script [CT]
The onselect event occurs when a user selects some text in a text field.
Tests: None
Assertion 18.2.3-35
(must) Intrinsic events: onselect = script [CT]
This attribute may be used with the INPUT and TEXTAREA elements.
Tests: None
Assertion 18.2.3-36
(must) Intrinsic events: onchange = script [CT]
The onchange event occurs when a control loses the input focus and its value has been modified since gaining focus.
Tests: None
Assertion 18.2.3-37
(must) Intrinsic events: onchange = script [CT]
This attribute applies to the following elements: INPUT, SELECT, and TEXTAREA.
Tests: None
Assertion 18.2.3-38
(should) It is possible to associate an action with a certain number of events that occur when a user interacts with a user agent.
Tests: None
Assertion 18.2.3-39
(must) Each of the "intrinsic events" takes a value that is a script.
Tests: None
Assertion 18.2.3-40
(must) The script is executed whenever the event occurs for that element.
Tests: None
Assertion 18.2.3-41
(must) The syntax of script data depends on the scripting language.
Tests: None
Assertion 18.2.3-42
(must) Control elements such as INPUT, SELECT, BUTTON, TEXTAREA, and LABEL all respond to certain intrinsic events.
Tests: None
Assertion 18.2.3-43
(may) When control elements do not appear within a form, they may be used to augment the graphical user interface of the document.
Tests: None
Assertion 18.2.3-44
(must) "document.write" or equivalent statements in intrinsic event handlers create and write to a new document rather than modifying the current one.
Tests: None
Assertion 18.2.4-1
(may) Scripts that are executed when a document is loaded may be able to modify the document's contents dynamically. The ability to do so depends on the scripting language itself (e.g., the "document.write" statement in the HTML object model supported by some vendors).
Tests: None
Assertion 18.2.4-2
(may) The dynamic modification of a document may be modeled as follows:
1. All SCRIPT elements are evaluated in order as the document is loaded.
2. All script constructs within a given SCRIPT element that generate SGML CDATA are evaluated. Their combined generated text is inserted in the document in place of the SCRIPT element.
3. The generated CDATA is re-evaluated.
Tests: None
Assertion 18.2.4-3
(must) HTML documents are constrained to conform to the HTML DTD both before and after processing any SCRIPT elements.
Tests: None
Assertion 18.3.1-1
(author)(must) Start tags and End tags for NOSCRIPT are required.
Tests: None
Assertion 18.3.1-2
(must) The NOSCRIPT element allows authors to provide alternate content when a script is not executed.
Tests: None
Assertion 18.3.1-3
(should) The content of a NOSCRIPT element should only be rendered by a script-aware user agent in the following cases:
1. The user agent is configured not to evaluate scripts.
2. The user agent doesn't support a scripting language invoked by a SCRIPT element earlier in the document.
Tests: None
Assertion 18.3.1-4
(must) User agents that do not support client-side scripts must render NONSCRIPT element's contents.
Tests: None
Assertion 18.3.2-2
(should) Some scripting engines, including those for languages JavaScript, VBScript, and Tcl allow the script statements to be enclosed in an SGML comment. User agents that don't recognize the SCRIPT element will thus ignore the comment while smart scripting engines will understand that the script in comments should be executed.
Tests: None
Assertion 18.3.2-3
(should) One of solution to the problem that user agents don't recognize the script element is to keep scripts in external documents and refer to them with the src attribute.
Tests: None
Assertion 18.3.2-4
(should) The JavaScript engine allows the string "<!--" to occur at the start of a SCRIPT element, and ignores further characters until the end of the line. JavaScript interprets "//" as starting a comment extending to the end of the current line. This is needed to hide the string "-->" from the JavaScript parser.
Tests: None
Assertion 18.3.2-5
(should) In VBScript, a single quote character causes the rest of the current line to be treated as a comment. It can therefore be used to hide the string "-->" from VBScript.
Tests: None
Assertion 18.3.2-6
(should) In Tcl, the "#" character comments out the rest of the line.
Tests: None
Assertion 18.3.2-7
(author)(should) Some browsers close comments on the first ">" character, so to hide script content from such browsers, you can transpose operands for relational and shift operators (e.g., use "y < x" rather than "x > y") or use scripting language-dependent escapes for ">".
Tests: None