NOTICE

Adfly Links not working Find Direct Links HERE

How to check and uncheck a checkbox with jQuery

Example form with Check box
<input type="checkbox" name="foo" value="bar" />
<input type="button" onclick="show_checked()" value="Show" />
<input type="button" onclick="set_checked(true)" value="On" />
<input type="button" onclick="set_checked(false)" value="Off" />

Check Status of Check box
   $('input[name=foo]').is(':checked')

Full JavaScript Code to On/Off Check Box
 

 function show_checked() {
    window.alert($('input[name=foo]').is(':checked'));
}
function set_checked(checked) {
    $('input[name=foo]').attr('checked', checked);
    //$('input[name=foo]').prop('checked', checked);
}

.prop() can also be used instead of .attr()


0 comments :

Feel free to leave comment if you like above widget, have any questions or just say Hi! :)