home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Platinum Edition Using HTML 4, XML, and Java 1.2
(Publisher: Macmillan Computer Publishing)
Author(s): Eric Ladd
ISBN: 078971759x
Publication Date: 11/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


HTML Form Events

As you would expect, Microsoft’s Dynamic HTML supports the traditional onreset and onsubmit events associated with an HTML form’s Reset and Submit buttons. Each of these events is triggered when the corresponding button is clicked. If an event handler for the onsubmit event returns a value of false, the form is not submitted.

Other Events

The following list describes the other events supported by Microsoft’s implementation of Dynamic HTML. Note also that a collection of events is associated with the data binding capabilities of Dynamic HTML—these events are discussed later in this chapter.

  onabort—This event is triggered when the user aborts the download of an image, normally by pressing the Stop button.
  onerror—This event is triggered when an error occurs when loading an image or other Web browser object. You can suppress error messages that occur when an image fails to load by setting the onerror attribute in the element to “null.”
  onfilterchange—This event fires when a filter changes state or completes a transition from one state to another. Filter effects of Microsoft Dynamic HTML are discussed in the “Dynamic HTML Filters” section later in this chapter.
  onresize—This event is triggered when the object to which it is attached is resized.
  onscroll—This event is triggered when the user scrolls the window, either by using the scrollbar, arrow keys, or some other means.
  onselect—This event is triggered when the current selection changes. The event continues to fire as the mouse moves from character to character during a drag selection.
  onselectstart—This event is triggered at the beginning of a user-initiated select.

Using Dynamic HTML with Styles

Dynamic HTML works very well with another aspect of Internet Explorer for dynamically changing the formatting of elements in an HTML document: styles and style sheets. One property associated with all HTML tags—which, as you will recall, you can access through the all object—is that tag’s style. The style property, in turn, has properties of its own that you can access and change to immediately change the appearance of the Web page.

Listing 26.4 shows an example of dynamically changing the style of elements of an HTML document. In this example, the format is applied to two elements in different ways—either through an embedded style sheet created with the <STYLE> tag or through the STYLE attribute. No matter which way you do it, the script changes the format in response to the onMouseDown and onMouseUp events. Figures 26.5 and 26.6 show the before and after screen shots of this HTML document.


FIGURE 26.5  You can attach formatting styles to HTML elements in a variety of ways.


FIGURE 26.6  You can change formats and immediately update the Web browser window in response to any event.

Listing 26.4 Style1.htmDynamic HTML Can Change Document Styles


<HTML>
<HEAD>
<TITLE>Dynamic HTML and Styles</TITLE>
<STYLE>
   .mousedown {font-size:48pt;color:red}
   .mouseup {font-size:24pt;color:black}
</STYLE>
<SCRIPT LANGUAGE=“JScript”>
function changeStyles(mousedown) {
   if (mousedown) {
      document.all.tags(“H1”).item(0).className = “mousedown”;
      document.all.tags(“P”).item(0).style.fontSize = “24pt”;
   } else {
      document.all.tags(“H1”).item(0).className = “mouseup”;
      document.all.tags(“P”).item(0).style.fontSize = “12pt”;
   }
}
</SCRIPT>
</HEAD>
<BODY onMouseDown=“changeStyles(1)” onMouseUp=“changeStyles(0)”>
<CENTER>
<H1 CLASS=“mouseup”>Dynamic HTML and Styles</H1>
<HR>
<P STYLE=“font-size: 12pt”>
When you click the mouse, the script in this example will
dynamically change the style of the heading and of this
text. The script uses the <EM>className</EM> and
<EM>style.fontSize</EM> properties of the
<EM>all.tags.item</EM> object.
</P>
<HR>
</CENTER>
<ADDRESS>
Jim O’Donnell, <A HREF=“mailto:odonnj@rpi.edu”>odonnj@rpi.edu</A>
</ADDRESS>
</BODY>
</HTML>

Dynamic HTML and the Data Source Object

Another Dynamic HTML capability works hand in hand with Microsoft’s Data Source Object to enable what is called data binding. The Data Source Object is an ActiveX Control that references an external file to provide data for the HTML document. Dynamic HTML enables you to use the DATASRC and DATAFLD attributes to bind this data to HTML elements. This way, the data displayed within a document can be kept separate from the formatting. Also, after the data is transmitted to the client Web browser, the Data Source Object can perform operations on it locally.

Data Binding Events

A collection of events is associated with HTML elements that are data bound using the DATASRC and DATAFLD attributes. The following list describes these events:

  ondataavailable—This event is triggered as data arrives from an asynchronous data source object; how often it fires depends on the data source object.
  ondatasetchanged—This event is triggered when the data set used by a data source object changes.
  ondatasetcomplete—This event is triggered when all the data available to a data source object has been loaded.
  onrowenter—This event is triggered when the current row of data has changed, and new data values are available.
  onrowexit—This event is triggered just prior to a data source object changing the current row in response to new data.
  onbeforeupdate—This event is triggered before the transfer of data from an element to a data provider.
  onafterupdate—This event is triggered after the transfer of data from an element to a data provider.
  onerrorupdate—This event is triggered when the handler for the onbeforeupdate event cancels the data transfer and fires instead the onafterupdate event.

Data Binding Example

Listing 26.5 shows an example of data binding using the Data Source Object and Dynamic HTML. In this example, a data file of chapter, page count, and author information is bound to the columns of an HTML table. The Data Source Object’s SortColumn() method is attached to the table headings, using the onClick event. When a column heading is clicked, the table is sorted by the contents of that column and immediately redisplayed. Figures 26.7 and 26.8 show examples of this, with the table sorted either by chapter number or chapter title.


Previous Table of Contents Next


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.