Tuesday, 13 August 2013

Fire onblur event before onchange event

Fire onblur event before onchange event

I have a large form that contains several text input fields. Essentially,
I need to handle the onchange event for all fields and the onblur events
for some fields. When a change is made to a field and the field loses
focus, both events fire (which is the correct behavior). The only issue is
that I would like to handle the onblur event before I handle the onchange
event.
After some testing in ie and Firefox, it seems that the default behavior
is to fire the onchange event before onblur. I have been using the
following code as a test...
<html>
<body >
<input type="text" value="here is a text field"
onchange="console.log('Change Event!')" onblur="console.log('Blur
Event!')" >
</body>
</html>
Which brings me to my questions:
It seems that this behavior is consistent across browsers. Why does
onchange fire first?
Since I cannot handle the onblur event for every input element, is there a
way I can get onblur to fire before handling the onchange event?

No comments:

Post a Comment