78
Chapter 2
The onChange event is triggered any time the
value in a form eld changes, like when you type
in a new value, or clear the existing one.
onChange
<input type=”text”
name=”street”
onChange=”updateMap();” />
Here’s how you’d specify an
onChange event in HTML.
Triggered when:
Field is entered
Field is exited
Field is changed
Any JavaScript attached to the
onFocus event is run when a
eld or other page component gets
the focus, by tabbing into the eld
or by clicking on the component.
onFocus
<input type=”text” name=”state”
onFocus=”popupStates();” />
Here’s the
onFocus event
handler in action.
Triggered when:
Field is entered
Field is exited
Field is changed
onBlur is used to run code when a user leaves a
eld, by tabbing out of the eld or by clicking on
another form component.
onBlur
<input type=”text”
name=”zipCode”
onBlur=”validateZip();” />
This code runs when the
zipCode eld loses focus.
Triggered when:
Field is entered
Field is exited
Field is changed
Event handler roundup
You have lots of different ways to attach your JavaScript code to
your HTML pages. Here are just a few of the more popular event
handlers, and a brief review of how each works. Take a close look;
you’ll be using one of these on the next page...
Man, Break Neck pizza rocks. There’s
nothing like a breakfast of cold pizza, a
whipped latte from Starbuzz, and the
Webville Times to read.
<script>
var request...
function ...