Radio button is not working properly

James picture James · Oct 31, 2013 · Viewed 68.8k times · Source

In my web page I have placed some radio buttons. But these buttons are not working properly. I can check multiple buttons.

code:

<label for="abc" style="margin-top:-20px;margin-left:40px">xyz</label>
<input type="radio" id="abc" name="abc" >        
<label for="bcd" style="margin-top:-20px;margin-left:40px">abc</label>
<input type="radio" id="bcd" name="bcd" >
<label for="efg" style="margin-top:-20px;margin-left:40px">ccc</label>
<input type="radio" id="efg" name="efg" >

fiddle

I want to check only one button. Please any one help me.

Answer

Mr. Alien picture Mr. Alien · Oct 31, 2013

Because you've different value for name attribute, they should have a common name value, just like you group items.. for example

<input type="radio" name="group1" />
<input type="radio" name="group1" />
<input type="radio" name="group1" />

<!-- You can select any one from each group -->

<input type="radio" name="group2" />
<input type="radio" name="group2" />
<input type="radio" name="group2" />

Demo