17

Hi I have numbers of check boxes and below that I have a Button, which will filter data as per check box selection.. enter image description here

When I will click on filter button it will transfer to other page and when I click on back button the checkbox reamains checked.

but I want that when I click on back button then checkbox should be uncheck.

enter image description here

Any help.

Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
Java Curious ღ
  • 3,622
  • 8
  • 39
  • 63

4 Answers4

27

For those who have similar issues, add autocomplete="off" to checkbox might help.

https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion

ohkts11
  • 2,581
  • 2
  • 21
  • 17
16

You can reset the checkboxes on page load using jQuery

$('input:checkbox').prop('checked', false);

Demo (Checkbox will be never checked as onload am getting rid of checked property)

ondomready (Place the below code anywhere in your document)

$(document).ready(function(){
   $('input:checkbox').prop('checked', false);
}); 
Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
  • I have already taken ``, how to use this at page load ? – Java Curious ღ Dec 18 '13 at 05:53
  • @JavaCuriousღ Wait, I'll edit my answer, but for this you will need jquery library – Mr. Alien Dec 18 '13 at 05:55
  • Please note that [there is a better way to reset to the default value](http://stackoverflow.com/q/16913094/218196) (in the general case). – Felix Kling Dec 18 '13 at 06:08
  • @FelixKling Isn't that something which can be done using a simple `` or am missing something there? – Mr. Alien Dec 18 '13 at 06:10
  • @Mr.Alien: Well, it depends whether you want to do this programmatically (like in this case) or not. The point of my comment was that unchecking the checkboxes is not the same as resetting them, in the general case. – Felix Kling Dec 18 '13 at 06:12
  • @FelixKling yea well, cuz sometimes it's funny when some users go for complicated approach rather than a simple one.. :) always happens with JS-CSS solutions.. – Mr. Alien Dec 18 '13 at 06:13
  • True :) Btw, I just noticed that question I linked to is about a `select` elements but checkboxes have a similar property, called `defaultChecked`. – Felix Kling Dec 18 '13 at 06:15
  • @FelixKling Yea, I got confused cuz of that, so commented :) – Mr. Alien Dec 18 '13 at 06:16
2

You may use below code :

window.onbeforeunload = function() {
         //unchecked your check box here.  
      $("input[type='checkbox']").prop('checked', false)
 };
Yagnesh Agola
  • 4,556
  • 6
  • 37
  • 50
1

Try this when back button is clicked Use Jquery to clear the checkboxes

$("input[type='checkbox']").each( function() {
$(this).removeAttr('checked');
});
Sridhar R
  • 20,190
  • 6
  • 38
  • 35