How can a checkbox be checked/unchecked using JavaScript?
Once the checkbox is selected, we are calling prop() function as prop( "checked", true ) to check the checkbox and prop( "checked", false ) to uncheck the checkbox.
attr("checked","checked"); To uncheck the checkbox: $("#checkboxid"). removeAttr("checked");
<input type="checkbox" name="deadline" value="yes" <? = $checked ?> >
Javascript:
// Check document.getElementById("checkbox").checked = true; // Uncheck document.getElementById("checkbox").checked = false;
jQuery (1.6+):
// Check $("#checkbox").prop("checked", true); // Uncheck $("#checkbox").prop("checked", false);
jQuery (1.5-):
// Check $("#checkbox").attr("checked", true); // Uncheck $("#checkbox").attr("checked", false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With