Thursday, September 27, 2018

javascript - Checkbox value is always 'on'




this is my checkbox



HTML







JQuery



var eu_want_team = $('#eu_want_team').val();
alert(eu_want_team);



Its always displaying ON, is it checked or not. Whats the problem with it?


Answer



Use .is(':checked') instead: Working jsFiddle



var eu_want_team = $('#eu_want_team').is(':checked');
alert(eu_want_team);



or as @Itay said in comments you can use jQuery's .prop() to get the checked property value:



alert($("#eu_want_team").prop("checked"));

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...