tags:

views:

43

answers:

4

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" (unless I specify otherwise in my php).

When I refresh the page, if the box was checked, it will stay checked which is no-bueno because checking the box adds a dom element to my page via a function attached to the box. So the problem is if I refresh, the box is still checked, but the dom element doesn't exist (because I haven't fired the function and I don't want to unless the user checks the check box) but the box is ALREADY checked and I end up in opposite land where UN checking the box creates my dom element and checking it removes it.

Basically, the question is...

Is there a way to default a checkbox to unchecked without javascript?

BTW I haven't checked (no pun intended) in any browsers other than FF 3.5.10

A: 

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.

casablanca
yeah, I just hate adding more javascript to my page, as I'll be adding some to CHECK certain boxes. I guess I can take care of all that at once, but I'd just like to start with a clean slate.
Jascha
A: 

this works for ie autocomplete="off"

Grumpy
+4  A: 

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

Riateche
well then, there you go. Damn you FF! (just kidding, I love FF, I wish everybody used FF)
Jascha
Yea, what's annoying to web developers is, unfortunately, a desired behavior for web users. There have been many times when I've accidentally reloaded a page while writing a long post and was grateful that Firefox kept my form data.
Lèse majesté
A: 

Checkboxes are unchecked by default. Is there some sample code that you can post to show this happening?

spinon