Forum Moderators: open

Message Too Old, No Replies

checkbox state

         

Sylvester

5:40 pm on Sep 19, 2003 (gmt 0)

10+ Year Member



I have a form with some checkboxes on it. I want the state to be set on by default on the page. I see many websites like this. I have been reading the help, books, and a few websites that say to use the "checked" attribute. But when this runs, it does not work. When the user clicks on the checkbox and hits submit its OK. Just the pre-checked state thing.

Here is the original code snippet. I have added 'checked' in like a ton of different ways.

checked
CHECKED
checked="true"
checked="Yes"
and many many others

<input type="checkbox" name="Brochure" value="Yes" tabindex="12">

korkus2000

5:49 pm on Sep 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This should work.

<input type="checkbox" name="Brochure" value="Yes" tabindex="12" checked>

What happens when you do that?

too much information

5:50 pm on Sep 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't know if this will work, but you could try SELECTED instead of CHECKED

<input type="checkbox" name="Brochure" value="Yes" tabindex="12" SELECTED>

or maybe if you didn't insert the CHECKED attribute that way you should try that. This works for me with radio buttons.

*dang! that's two days in a row that I post just behind someone. :) Good answer k2000

Sylvester

8:12 pm on Sep 19, 2003 (gmt 0)

10+ Year Member



I tried selected too.

It simply does not come up pre-checked.

I have been using Dreamwaver. I can goto the checkbox properties and select the default state their. And in their WYSIWYG environment it shows checked. Then view in browser and its not checked. Upload to server and then test live and its not checked. -- I also did this my hand entering the HTML. And tried many different syntax.

The last test I just did was selected. I ran it from the server, then did view source. Scrolled thru the source and selected was in there. But its not checked.

Its like IE 6.02 or what ever the latest is, is simply ignoring this. Maybe its my machine? hmmm... Called friend. Had them test it. Nope does not work their either.

Sylvester

8:19 pm on Sep 19, 2003 (gmt 0)

10+ Year Member



Does it have to be all caps? hmm...

Looks like the answer is Yes. I guess there is a case I didnt try. Thanks.

victor

8:28 pm on Sep 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<input type="checkbox" name="field-name" checked="checked">

I use the above. It works for me, and validates to 4.01 strict. And it's all lowercase.

Sylvester

8:42 pm on Sep 19, 2003 (gmt 0)

10+ Year Member



victor, that one worked for me too.

Sylvester

8:52 pm on Sep 19, 2003 (gmt 0)

10+ Year Member



OK, now that I have gotten thru that. Too the heart of the matter. I was trying to add some .asp form validation. I wanted the form to remember checkbox state. I was using the following....

<input type="checkbox" name="Brochure" value="Yes" tabindex="12" <% if fBrochure = "Yes" then %> <%= CHECKED %><% end if %>>

the variable fBrochure does get set, as its what get send to me in the email. It is set back at the top of the page after the submit button gets pressed. So I think that part is ok. But it does not remember the state.

This was/is not appearing to work. I was thinking it was my .asp code. I figured I could prove that. Thats when I tried to back up and just make sure 'checked' worked. It didnt seem to work either. So I spent this morning messing with that. Now that that seems to be out of the way, back to the original goal.

Zaphod Beeblebrox

10:55 am on Sep 20, 2003 (gmt 0)

10+ Year Member



checked="" means unchecked, anything else, like "on" or "checked" means checked.