Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

checked="checked" not working in chrome

Tags:

<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/

like image 853
chuckieDub Avatar asked Jun 05 '13 22:06

chuckieDub


People also ask

How do you check checkbox is checked or not?

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.

How to set default checked checkbox in HTML?

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.

How do you use checked in HTML?

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.

Which attribute will make a checkbox selected ticked by default?

The checked content attribute is a boolean attribute that gives the default checkedness of the input element.


2 Answers

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

like image 149
taco Avatar answered Sep 27 '22 20:09

taco


@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 ;)

like image 27
Umesh Patil Avatar answered Sep 27 '22 19:09

Umesh Patil