I'm currently facing a weird issue with the onchange event. I have a web application where each blur event makes a call the webserver to store the value of the textfield. I only want to trigger that ajax
call when something has changed, so i track the onchange event on each textfield to set a flag if something has changed.
The onchange event always fires to first time when i click outside of a textfield even if i didn't change anything in the field.
I narrowed it down to the following: A prefilled textfield always fires the onchange-event the first time you leave the textfield. An initially empty textfield does not fire the onchange event.
Does anybody has any idea why this happens and how can i prevent it from happening?
Thanks for the help.
Sample code (IE 8 on Windows 7 computer):
script:
$('input[type=text]').each(function() {
$(this).blur(onBlur);
$(this).change(onChange);
<input type="text" id="ctrlName" class="ui-widget-content small" value="abc" /> -- This field fires onchange-event, even if nothing has changed
<input type="text" id="ctrlLength" class="ui-widget-content small" value="" /> -- this field does not fire the onchange event as expected.