I realized that on a webpage, when a form's UI (checkbox, dropdown list, etc) is changed programmatically, the event handler (onchanged) is not fired? Is this a standard rule -- that when a control is changed programmatically, the event handler will never get triggered? Is there any exception?
views:
22answers:
1
+2
A:
That is correct, unless as Pointy "pointed" out, you are also firing the event. In jQuery this is as easy as adding a call to .change()
in your code that is changing the form.
Ex. -
Html:
<form id="aForm">
<input></input><br />
<input></input><br />
<input type="checkbox"></input><br />
<input type="checkbox"></input><br />
</form>
jQuery:
$('#aForm').change(function() {
alert('Your form hath changed!');
})
$('#aForm').hide(function(){
$(this).change();
});
jsFiddle working example - http://jsfiddle.net/qGLc2/
HurnsMobile
2010-07-12 17:43:15