Scripting is incredibly important on the world wide web - without it, the web would be a different experience. HTML's role in scripting is relatively limited, but what it does do is to act as a facilitator - it permits the use of scripts in HTML.
HTML essentially has two roles; firstly, in allowing scripts to react to certain events, and secondly in allowing scripts to be included in HTML.
The SCRIPT element is used to include scripts within HTML documents. E.g.:
From an HTML point of view, the SCRIPT element is extremely simple. There are really only a very few points of note:
Although the number of browsers that would otherwise render the content is minuscule, it is still worth including them. Note also that to avoid errors in the language, the comment close tag must be hidden from the script parser. E.g.,:
The NOSCRIPT element is used to provide alternate content for browsers that are not currently supporting script. E.g.,
Certain actions (such as mouse clicks) generate an event. HTML allows these to be reacted by scripting languages by its use of the ONxxxx event handlers.
Since there is no way of declaring the type of scripting languages used on attributes (e.g., onload), if you use the intrinsic events, you must set the default script type for the document.
This is best done by setting the Content-Script-Type HTTP header to the desired value, but failing that, you can set a header equivalent:
If you fail to set a default script type and use the intrinsic events, your document is WRONG.
|onload||FRAMESET or BODY||Means completely loaded|
|onunload||FRAMESET or BODY||Means completely loaded|
|onmousedown||most elements||mouse is pressed down over an element|
|onmouseup||most elements||mouse is released over an element|
|onmouseover||most elements||mouse is moved over an element|
|onmousemove||most elements||mouse is moved while over an element|
|onmouseout||most elements||mouse moved away from an element|
|onfocus||LABEL, INPUT, SELECT, TEXTAREA, BUTTON||Element has focus through tabbing to it or by being given it by the mouse|
|onblur||LABEL, INPUT, SELECT, TEXTAREA, BUTTON||Element has focus through tabbing to it or by being given it by the mouse|
|onkeypress||most elements||key is pressed and released over an element|
|onkeydown||most elements||key is pressed down over an element|
|onkeyup||most elements||key is released over an element|
|onsubmit||FORM||when form is submitted|
|onreset||FORM||when form is submitted|
|onselect||INPUT and TEXTAREA||applies when text in a text field is selected|
|onchange||INPUT, SELECT and TEXTAREA||Control loses focus having had its value changed prior to losing the focus.|
The next section of this HTML tutorial deals with forms.