Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
84
rated 0 times [  91] [ 7]  / answers: 1 / hits: 159412  / 12 Years ago, thu, may 31, 2012, 12:00:00

I've seen the three implementations of pre-selecting a checkbox. I started off using checked=checked because I thought it was the proper way (never did like the checked=yes however). I am thinking of changing to checked=true as it seems more readable and is easier to code the JavaScript. Note that this same question applies to other attributes such as disabled=disabled versus disabled=true. As long as I am consistent, is using true the preferred approach? Thank you



<input type=checkbox checked=checked value=123 name=howdy />
<input type=checkbox checked=true value=123 name=howdy />
<input type=checkbox checked=yes value=123 name=howdy />

More From » html

 Answers
3

Only checked and checked=checked are valid. Your other options depend on error recovery in browsers.



checked=yes and checked=true are particularly bad as they imply that checked=no and checked=false will set the default state to be unchecked … which they will not.


[#85242] Wednesday, May 30, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
arlethjeanettep

Total Points: 506
Total Questions: 96
Total Answers: 79

Location: Liberia
Member since Tue, Mar 14, 2023
1 Year ago
;