Skip to content Skip to sidebar Skip to footer

Checkbox Stays Checked On Page Refresh

This a pretty simple question (I assume). Probably a repost, but I couldn't find the answer here... so here we go. I have a checkbox on a page that I want to default to 'unchecked

Solution 1:

See http://weblogs.mozillazine.org/gerv/archives/2006/10/firefox_reload_behaviour.html (first comment):

It’s done that way on purpose so if you tap the refresh button you don’t lose your work. There’s an entry in Bugzilla somewhere that’s been WONTFIXed asking for a regular refresh to always reset the form entirely. Basically it’s a backwards-compatibility thing — every browser since NS1.0 (maybe even Mosiac) has done that.

Dynamically-generated pages don’t even reset themselves, though if the expiration is set to 0 and you hit the back button it will give you a fresh form. Also, if the form itself changes (add or remove elements, change the action, etc.) the for will reset on a reload. I haven’t tested it, but setting the form name to something random (assuming you don’t need the name for JS access) might just work. Like ”> in PHP.

As you said, forcing a refresh clears the form, and resetting it does too. Would something like do what you want (again, not tested)?

Solution 2:

this works for ie autocomplete="off"

Solution 3:

Sure:

document.getElementById('my_checkbox').checked = false;

Oops, I missed the part about no JS. As far as I know, Firefox retains page state on refresh, so I guess there's no other way.

Solution 4:

In fact, you just have to add the <form> tag with attribute autocomplete="off":

<formautocomplete="off"><labelfor="checkbox"><inputtype="checkbox"id="checkbox"></label></form>

Post a Comment for "Checkbox Stays Checked On Page Refresh"