<input type="checkbox" name="Type[]" value="Red" checked="checked" /><span class="space-right">Red</span>
Properly sets checkbox to checked in firefox and safari but not chrome. Can't find any info about this online.
Anyone know how to fix this?
Have also tried the naked checked
as well as checked="true"
Not looking for a js solution, thank you.
Edit: The answer by taco below describes what the issue was. When using forms and input elements, the elements must be properly nested in <td></td>
tags or the checked="checked"
has no effect. Here is an example of a jsfiddle that proves this to be true on chrome 29.0.1547.57: http://jsfiddle.net/LnL7b/
prop() and is() method are the two way by which we can check whether a checkbox is checked in jQuery or not. prop(): This method provides an simple way to track down the status of checkboxes. It works well in every condition because every checkbox has checked property which specifies its checked or unchecked status.
If you wanted to submit a default value for the checkbox when it is unchecked, you could include an <input type="hidden"> inside the form with the same name and value , generated by JavaScript perhaps.
The checked attribute is a boolean attribute. When present, it specifies that an <input> element should be pre-selected (checked) when the page loads. The checked attribute can be used with <input type="checkbox"> and <input type="radio"> . The checked attribute can also be set after the page load, with a JavaScript.
The checked content attribute is a boolean attribute that gives the default checkedness of the input element.
I was able to replicate this issue on Google Chrome Version 28.0.1500.95.
<table> <tr> <td>test</td> <input type="radio" name="foo" value="bar" checked="checked"> </tr> </table>
I broke the table by improperly nesting a radio button. This somehow causes Google Chrome to not mark the input radio as checked.
jsfiddle example - broken and jsfiddle example - working
@Abhay's answer worked for me, I dont know why people negative marking it. I had 2 radio groups sharing same name like below,
<input type="radio" name="gender" value="male" checked> Male<br> <input type="radio" name="gender" value="female"> Female<br> <input type="radio" name="gender" value="other"> Other
Then again at the bottom of the page,
<input type="radio" name="gender" value="male" checked> Male<br> <input type="radio" name="gender" value="female"> Female<br> <input type="radio" name="gender" value="other"> Other
So what happening was browser's getting ambiguity and it was selecting only the bottom one not the upper one.
Hope this will help someone.
Enjoy ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With