Beginning JavaScript | 18
|
[previous] [next] |
Beginning JavaScript
Select Element Events
Select elements have three event handlers, onblur, onfocus, and onchange. We've seen all these events before. We saw the onchange event with the text box element, where it fired when focus was moved away from the text box and the value in the text box had changed. Here it fires when the user changes which option in the list is selected.
Try It Out  Using the Select Element for Date Difference Calculations
Let's take a look at an example that uses the onchange event and makes good use of the select element in its drop-down list form. Its purpose is to calculate the difference, in days, between two dates as set by the user via drop-down list boxes.
Call the example ch6_examp9.htm and load it into your Web browser. You should see the form below, but with both date boxes set to the current date.

If you change any of the select boxes, then the difference between the days will be recalculated and shown in the text box.
|
[previous] [next] |
and
Created: February 7, 2001
Revised: February 7, 2001
Created: February 7, 2001
Revised: February 7, 2001
URL: http://webreference.com/programming/javascript/beginning/chap6/

Find a programming school near you