Deselect all checkboxes when returning to the previous page

3

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?

    
asked by anonymous 22.12.2017 / 20:33

3 answers

1

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.

    
22.12.2017 / 20:44
3

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.

    
22.12.2017 / 20:41
1

When the page loads, use the code below on the page

For jQuery version < 1.6

$(document).ready(function(){
  $("checkbox").attr('checked', false);
});

For jQuery version > 1.6

$('#myCheckbox').prop('checked', false);
    
22.12.2017 / 20:45