I'm developing a software and noticed a flaw: when the user returns to the previous page, the checkboxes are still marked.
How do I uncheck all of them?
As you have not reported if you are using jquery as a framework in your project, I am considering that yes, otherwise edit the code for your needs
<input type="checkbox" checked='true' class='check' name="tecnologia" value="java"/>JAVA
<input type="checkbox" checked='true' class='check' name="tecnologia" value="html"/>HTML
<input type="checkbox" checked='true' class='check' name="tecnologia" value="css"/>CSS
<input type="checkbox" checked='true' class='check' name="tecnologia" value="javascript"/>JAVASCRIPT
After reading the DOM, perform a function by callback to uncheck:
$(document).ready(function(){
$(".check").removeAttr("ckecked");
}
remembering what to use in onready so you do not have a chance to try to remove the checked attribute without loading the html correctly.
A simple addition of jQuery code unchecks everything both in page loading and back to it:
$("input[type='checkbox']").prop('checked', false);
If checkbox
has class
in common:
$("input.class").prop('checked', false);
or $(".class").prop('checked', false);
Or belong to a div
with a id
:
$("#div input[type='checkbox']").prop('checked', false);
Or a single form
on the page:
$("form input[type='checkbox']").prop('checked', false);
Note that the
.removeAttr
and.attr
methods do not work for change checked or disabled properties in newer versions of jQuery.
When the page loads, use the code below on the page
$(document).ready(function(){
$("checkbox").attr('checked', false);
});
$('#myCheckbox').prop('checked', false);