[Javascript] Programmatically set onchange event for textbox
Brian L. Matthews
blmatthews at gmail.com
Wed Oct 4 00:24:30 CDT 2006
><input name="txtCardNumber" type="text" maxlength="16" id="txtCardNumber" />
>[...]
>So, I have the following code and when the page loads, I do get the "Textbox
>found" message. However, when I type in the text box, I do not get the "Card
>Number Typed" alert.
onchange only fires when the field loses focus (i.e. you tab out or
click the page somewhere outside the field). That's often sufficient
(it usually doesn't make sense to do field validation on a partially
typed field). If you want to validate the first digit as soon as it's
typed, look into the onkey events, but make sure you read about
browser compatibility (<http://www.quirksmode.org/> is a good site,
I'm sure there are others).
Brian
More information about the Javascript
mailing list