Mike Levin SEO

Future-proof your technology-skills with Linux, Python, vim & git... and me!

OnChange vs. OnBlur

by Mike Levin SEO & Datamaster, 04/24/2006

Well, it’s a VERY nuanced point, but there appears to be a way to circumvent an onchange JavaScript validation check that doesn’t exist with onblur. The general wisdom is that it’s better to use onchange, because onblur can cause funky behavior. For example, onblur can cause user interface lockup if you have two sequential fields each with a check that causes a modal pop-up alert. Simply tabbing once to get to the second field causes a catch-22 condition. You can’t start typing in the second field because of the pop-up from the first field, but you can’t get back to the first field because of the validation on the second field.

Well, I’m here to say that if you just don’t use modal pop-up’s for validation, it is actually better to use onblur, because it avoids a loophole that I found in Internet Explorer. It exists in MSIE 6.0.3790.1830 and MSIE7 beta 7.0.5335.5. When the predictive field completion feature is turned on, it creates a dropdown menu on a field lets you arrow-key down to a previously typed value. This is common on name and email fields. When you fill in a field using this feature, it seemingly lets you advance to the next field as if you tabbed, but without triggering an onchange event on the current field! So, I’m changing my app to use the previously frowned-upon onblur event. It works solidly under both MSIE and FireFox.