Can't cancel the onchange event for my HTML checkbox
html, javascript, jquery
Solution
Bind to the Click event: example
$(document).ready(function() {
$('#checkbox1').click(function(event) {
if (flag) {
CancelEvent(event);
return event.returnValue;
}
SomeOtherStuff('this method has real functionality too');
});
});
Change is a little to late in the event structure to cancel the action that already happened. In addition, the return value was being omitted. So I added it to the event handler.
Problem
I have a working example of this but I'm not sure why my implementation isn't working. Can somebody please help? I'm missing something and I need another set of eyes to find it for me. :) JSFiddle demo <-- see code here. I'm trying to reproduce the functionality used here. I seem to be a little confused about passing/accessing the `event` variable around. Thanks!! :-)