Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checkbox is checked even though checked=false

Tags:

html

checkbox

I want to uncheck my Checkbox with Javascript, but it didn't work. And then I tried to set the checked property to false directly in HTML, but not even that worked: (I tried checked="false" too...)

My HTML:

<input type="checkbox" id="dateCheckbox" checked=false >
<label for="dateCheckbox"> Keinen Zeitraum angeben</label>

Result:

result

Why is it still checked?

like image 822
G-Unit Avatar asked Nov 23 '25 03:11

G-Unit


1 Answers

HTML5 does not use true or false for boolean attributes. Boolean attributes are true by specifying the attribute name alone, and a false value is the omission of the attribute.

(For XHTML5, you provide the attribute-name as the value in order to conform to XML's rules for attributes):


So for an unchecked checkbox, change this:

<input type="checkbox" id="dateCheckbox" checked=false >

To this (HTML5 and XHTML5):

<input type="checkbox" id="dateCheckbox">

For a checked checkbox, change this:

<input type="checkbox" id="dateCheckbox" checked=true >

To this (HTML5):

<input type="checkbox" id="dateCheckbox" checked>

or this (XHTML5):

<input type="checkbox" id="dateCheckbox" checked="checked" />
like image 133
Dai Avatar answered Nov 27 '25 22:11

Dai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!