1

http://www.w3schools.com/html/tryit.asp?filename=tryhtml_checkbox

Try it with the input below:

<html>
<body>

<form action="">
<input type="checkbox" name="vehicle" value="Bike" checked="false" /> I have a bike<br />
<input type="checkbox" name="vehicle" value="Car" /> I have a car 
</form>

</body>
</html>

I have a bike has checked="false" still that is checked why?

rid
  • 61,078
  • 31
  • 152
  • 193
Kuttan Sujith
  • 7,889
  • 18
  • 64
  • 95
  • 1
    The mere presence of the `checked` attribute will check the check box. My preferred syntax is ``. – Šime Vidas Nov 05 '11 at 14:23
  • Also take a look at http://stackoverflow.com/questions/2874949/what-is-the-syntax-for-a-checked-checkbox-in-html. – rid Nov 05 '11 at 14:24
  • The value of "checked" is mandatory for XHTML (because XML specifies that any attribute must have a value, even if it's empty), and, by convention, it's `checked="checked"`. It's not however mandatory for HTML. – rid Nov 05 '11 at 14:25
  • @Radu Cant' we just let go of the XHTML syntax at last? XHTML is dead, it's over.... – Šime Vidas Nov 05 '11 at 14:27
  • @Šime Vidas, I have no problem with letting go of XHTML (I just said that it's not mandatory in HTML). I'm merely explaining where the value comes from. The HTML standard specifies that an attribute of "checked" will make an input checked. XML however insists that each attribute must have a value. Therefore, in XHTML, you need to specify a value for checked, whatever value that might be (even "false" or "no" will do). This introduces confusion. – rid Nov 05 '11 at 14:29
  • @Radu Yes, I agree on the facts. It is my opinion that XHTML should not be spoken of in a way that implies that it's equal to HTML. When mentioned, it should be made clear that XHTML was an failed attempt and that the HTML syntax is the preferred way to write web-pages. – Šime Vidas Nov 05 '11 at 14:50

2 Answers2

4

"false" has no meaning. The HTML rendering engine looks to see if the "checked" attribute is present, regardless of what value it contains. If it's present (whatever the value), then the checkbox will be checked. If it's not present, then it won't be checked.

rid
  • 61,078
  • 31
  • 152
  • 193
0

u have used checked=false. This is not the right method to uncheck the checkbox. use as follows.

<form action="">
<input type="checkbox" name="vehicle" value="Bike" checked="checked">I have a bike<br>
<input type="checkbox" name="vehicle" value="Car" checked="">I have a car 
</form>

checked="checked" will check the checkbox. checked="" will uncheck it. you can also use checked instead of checked="checked".

GomathyP
  • 147
  • 2
  • 8