Pre selected checkbox in a form

I wonder if it is possible to pre select an checkbox input at all?
This is how I try to do it, which won’t work

<input type="checkbox" name="favorite2" id="favorite2" value="2" selected="selected" />

I’m using doctype XHTML 1.0 Strict and I get the following error message from the validation:

Line 29, column 76: there is no attribute “selected” (explain…).

…rite2" id=“favorite2” value=“2” selected=“selected” />
There are no errors in the rest of the document.

I can post the hole page (44 lines) if it’s necessary.

Thanks. :slight_smile:


[font=Courier][color=#ff8000]<input type=[/color][color=#0000ff]"checkbox"[/color][color=#ff8000] name=[/color][color=#0000ff]"favorite2"[/color][color=#ff8000] id=[/color][color=#0000ff]"favorite2"[/color][color=#ff8000] value=[/color][color=#0000ff]"2"[/color][color=#ff8000] checked[/color][color=#ff8000] />[/color][/font]


Try that.

you should use:
instead of

XHTML does not allow attribute minimisation, so you can’t just use the word checked on its own.

Aahh those small silly mistakes. Guess I’ve been doing to much PHP back end programming lately. :smiley:

Thank you RichPearce. :slight_smile: