PDA

View Full Version : OnFocusChange


tsbarnes
03-24-2003, 08:17 PM
Hey everyone,

I am looking to right a function that will validate a certain form field upon leaving that field.

For example:

I have an email field and once my cursor gives focus to that field and then I move to the next field I want it to validate the email field? I hope this makes sense.

Thanks,

Tsbarnes

x_goose_x
03-24-2003, 08:23 PM
onBlur="func();"

boywonder
03-25-2003, 12:00 AM
My 2 cents: If this validation is important, you might consider using the form's onsubmit event to validate instead. Or if it's REALLY important, and if you're able then validate on the back end.

Using onblur to 'validate' a field is quite useless, (some would say that about client side validation as a whole). However perhaps it does suit your purposes in this case.

arnyinc
03-25-2003, 02:53 PM
Originally posted by boywonder
you might consider using the form's onsubmit event to validate instead.

Is onsubmit better/safer than onblur? Onblur always seemed kind of flaky to me (easier to avoid validation), but any sort of testing and playing around with it that I did, it seemed to work just like any other event.

brothercake
03-25-2003, 03:43 PM
more to the point, it saves you having to bind event handlers to each element; you just validate the whole form before submission; it's much less painful to program :)

boywonder
03-25-2003, 03:55 PM
Right! thanks.
In addition, onblur as validation can be easily bypassed (perhaps even unintentionally) just by failing to give the field focus in the first place.