Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What values for checked and selected are false?

Tags:

html

w3c

I think according to W3 spec, you're supposed to do

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

And

 selected="selected" 

But, most browsers will accept it you just write "CHECKED" and don't give it a value. So, what if you do include the attribute, are there any values that would be (consistently) considered false?

like image 421
mpen Avatar asked Nov 19 '10 19:11

mpen


People also ask

What is the value of checkbox if it is not selected?

If a checkbox is unchecked, it doesn't get sent, so setting it's value to 0 if it isn't checked isn't going to help - it will always return NULL.

How do you set a checkbox to false value?

val( checkbox[0]. checked ? "true" : "false" ); This will set the value of the checkbox to "true" or "false" ( value property is a string) , depending whether it's unchecked or checked .

What is the value of a checked checkbox?

If a checkbox is marked or checked, it indicates to true; this means that the user has selected the value. If a checkbox is unmarked or not checked, it indicated to false; this means that the user has not selected the value.

How do you check if a checkbox is true or false?

Checking if a checkbox is checked First, select the checkbox using a DOM method such as getElementById() or querySelector() . Then, access the checked property of the checkbox element. If its checked property is true , then the checkbox is checked; otherwise, it is not.


1 Answers

There are no values that will cause the checkbox to be unchecked. If the checked attribute exists, the checkbox will be checked regardless of what value you set it to.

<input type="checkbox" checked />  <input type="checkbox" checked="" />  <input type="checkbox" checked="checked" />  <input type="checkbox" checked="unchecked" />  <input type="checkbox" checked="true" />  <input type="checkbox" checked="false" />  <input type="checkbox" checked="on" />  <input type="checkbox" checked="off" />  <input type="checkbox" checked="1" />  <input type="checkbox" checked="0" />  <input type="checkbox" checked="yes" />  <input type="checkbox" checked="no" />  <input type="checkbox" checked="y" />  <input type="checkbox" checked="n" />

Renders everything checked in all modern browsers (FF3.6, Chrome 10, IE8).

like image 127
mpen Avatar answered Oct 19 '22 17:10

mpen