|
To access the contents, click the chapter and section titles.
HTML 4.0 Sourcebook
Using META to Specify A Default Script LanguageIf neither TYPE nor LANGUAGE is given, then the browser needs to guess at the language used by the document script. To avoid the possible confusion that may arise from this process, an author can use a META element to specify the default scripting language in a document. The form is: <META HTTPEQUIV=ContentScripttype CONTENT=type/subtype> where type/subtype is the MIME type of the default document scripting language. Note that this format indicates that the default script type can also be indicated by an HTTP server response header field of the form: Contentscripttype: type/subtype See Chapter 9 for more information about HTTP headers and the HTTP protocol. Script Interaction with HTML ElementsScripting languages become much more dynamic when they are bound to user input elements. In HTML, the basic user input elements are the anchor element A and the various FORM elements. Both JavaScript and VBScript provide bindings to these elements via the event handlers listed in Table 7.5these event handlers are triggered by the events described in the table. For example, an onClick event can be triggered when a hypertext link is selected (clicked), while the onLoad event is triggered whenever a document or frame is loaded onto the display. Event handlers are attached to specific elements via special event handling attributes. These attributes have names matching the events they handle (the attribute names are case insensitive) and take as their value the function that should be invoked when the event takes place. Consider, for example, the following markup: <INPUT TYPE=button NAME=butt1 VALUE=foo ONCLICK=alert(Uh oh you pressed the Foo Button! );> The ONCLICK attribute binds this button (named butt1) to the indicated JavaScripthere a simple alert popup window. When the user presses this button, the onClick event is triggered, and the browser will pop up an alert window containing the given message string. To support clientspecific form processing and user interaction, Netscape introduced a TYPE=button INPUT element. This is used for clientside actions onlythe name and value associated with a TYPE=button element are never sent with the form data when a FORM is submitted to a remote server. This is illustrated in Figure 7.43, which shows a FORM containing two INPUT elements: one of TYPE=button, (taken from our previous example) and the other of TYPE=submit. Figure 7.44 shows the document displayed after the user has selected the button labeled foo. This button is tied by the onClick event handler to the JavaScript alert() function, so that pressing this button causes the visible popup alert menu. If, instead, the user presses the submit button, the accessed URL is (omitting the leading part of the URL) ..../cgi/prog.pl?submit=Submit+It%21 which contains only the encoded data from the TYPE=submit buttonthe name and value from the TYPE=button element are absent. Figure 7.43 Example HTML document illustrating the TYPE=button input element and event handling. The display of this form by Internet Explorer 3 is shown in Figure 7.44. <HEAD><TITLE> Scripting Test</TITLE></HEAD> <BODY> <H2>Buttons and More Buttons</H2> <BLOCKQUOTE> <FORM ACTION=/cgi/prog.pl METHOD=get> <H3> A Simple FORM Example</H3> <INPUT TYPE=button NAME=butt1 VALUE=foo ONCLICK=alert(Uh oh you pressed the Foo Button! ); > <B>The FOO BUTTON!</B><BR> <INPUT TYPE=submit NAME=submit VALUE=Submit it!> </FORM> </BODY></HTML>
HTML Elements and Event HandlersWith Netscape Navigator 4 and Internet Explorer 4, there are 12 commonly supported event handlers (listed in Table 7.5) and 19 different HTML elements that accept event handling attributes. However, only a few event handlers are appropriate for any given elementfor example, the onUnload event, triggered when the user leaves document, is irrelevant to the AREA (clientside imagemap data) element, but appropriate to BODY and FRAMESET. To help keep track of which handlers go where, Table 7.6 lists elements that take event handlers, alongside the supported handler types. Note that support for these handlers may be buggy, or nonexistent, depending on the browser. Some common versionspecific limitations are indicated in the table captions, but more definitive information is found in the book JavaScript, The Definitive Guide, by David Flanagan. Internet Explorer 4 supports all these event handlers, plus many others that will be discussed later, in the section titled Advanced Scripting and the Document Object Model. Dynamic ScriptsAs mentioned, HTML output generated by scripts is staticonce it is displayed on the page, it can in general only be modified by erasing the page and starting again. More dynamic interaction is possible using FORM textlevel elementsscript programs can dynamically update the value content of INPUT TYPE=text and TEXTAREA elements (they can actually modify the content of any VALUE attribute). This allows for autotabulating forms (for example, summing a column of elements, as in a spreadsheet) or dynamic generation of form field data using data derived from user input or other sources.
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |