Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do my jQuery checkbox.change events only fire on leavefocus in IE but they happen onclick in FF?

    $(".feature").change(function(){
        getProductSelections();
    });

ARRRGHH!!

like image 487
MetaGuru Avatar asked Oct 01 '09 03:10

MetaGuru


People also ask

How can create checkbox click event in jQuery?

change() updates the textbox value with the checkbox status. I use . click() to confirm the action on uncheck. If the user selects cancel, the checkmark is restored but .

How do you check checkbox is checked or not Onchange jQuery?

To check whether a Checkbox has been checked, in jQuery, you can simply select the element, get its underlying object, instead of the jQuery object ( [0] ) and use the built-in checked property: let isChecked = $('#takenBefore')[0]. checked console. log(isChecked);


1 Answers

Web Bug Track:

The onchange event can be attached (inline or as an event handler) to any form element. It fires whenever the value of the form field changes. Unfortunately, the behavior is a bit strange in IE, in that for a checkbox, or a radio button field, the event doesn't fire when it is supposed to (right when you click the option you want to choose), but instead it only fires, when you click elsewhere on the page/form, or if you explicitly call blur(); on the field.

And the work around suggested is:

<input type="radio" name="foo" value="Green" onclick="alert(this.value);"/>Green
<input type="radio" name="foo" value="Blue" onclick="alert(this.value);"/>Blue
like image 66
Kredns Avatar answered Oct 07 '22 15:10

Kredns