Uncheck all checkboxes by going back to the previous page

Asked

Viewed 381 times

3

I am developing a software and I noticed a flaw: when the user returns to the previous page, the checkboxes are still marked.

How I clear them all?

inserir a descrição da imagem aqui

  • In the checkbox add: autocomplete="off"

  • @juniorb2ss thanks!! solved

3 answers

3

A simple addition of jQuery code unchecks everything, both when loading the page and when returning to it:

$("input[type='checkbox']").prop('checked', false);

If the checkbox have a 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 in a single form on the page:

$("form input[type='checkbox']").prop('checked', false);

It is worth remembering that the methods .removeAttr and .attr do not work for change properties checked or disabled in newer versions jQuery.

  • Your answer is very detailed up

  • 1

    @I_like_trains :D.. thanks!

1


As you did not inform if you are using jquery as a framework in your project I am considering that yes, otherwise edit the code 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 callback function to uncheck :

$(document).ready(function(){
    $(".check").removeAttr("ckecked");     
}

remembering that you should use onready to have no chance of trying to remove the checked attribute without having loaded the html correctly.

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);
  • @Guilhermenascimentop. As restoration?

  • @Guilhermenascimentop. Made

Browser other questions tagged

You are not signed in. Login or sign up in order to post.