tags:

views:

26

answers:

4

Hello,

Why is this line not working?

<input type="checkbox" checked="no"/>
                    <input type="checkbox" checked="false"/>

Even though i have specified no and false in checkbox value both are checked by default.

Thanks in advance :)

+2  A: 

changing it to this will make the first unchecked, and the second checked :

 <input type="checkbox" />
 <input type="checkbox" checked />

To make the checkbox unchecked you need to remove the word "checked".

NimChimpsky
+2  A: 

Try this -

<input type="checkbox" checked/>

The attribute "Checked" will keep your checkbox checked by default. If you do not have this attribute mentioned, then the checkbox will be unchecked by default.

Sachin Shanbhag
will give a validation error on markup
Grumpy
+1  A: 

Even though i have specified no and false in checkbox value both are checked by default.

this is default behaviour for boolean values in HTML elements.

Only removing the checked attribute altogether will make the element not checked.

The background is in On SGML and HTML:

Some attributes play the role of boolean variables (e.g., the selected attribute for the OPTION element). Their appearance in the start tag of an element implies that the value of the attribute is "true". Their absence implies a value of "false".

Boolean attributes may legally take a single value: the name of the attribute itself (e.g., selected="selected").

Pekka
A: 
<input type="checkbox" checked="checked" />

this will pass html validation

Grumpy
Actually, it will pass xhtml validation.
Chouchenos