Reputation: 33
As we know that, Radio button function in HTML allows user to Select one of options on page. But when I used "radio" . I am able to select all of options on a page! Please help me with it! Here's example of those types of code:
<!DOCTYPE html>
<html>
<head> <title> Survey </title> </head>
<body LEFTMARGIN="500" TOPMARGIN = "200"><font face = "BROADWAY">
<input type="radio" name="m"/>MS Dhoni <br />
<input type="radio" name="v" />Virat Kohli<br />
<input type="radio" name="s"/> Sachin Tendulkar <br/></font>
</body>
</html>
Upvotes: 0
Views: 59
Reputation: 5891
You have to give them the same name but a different value.
Like this:
<input type="radio" name="sex" value="male"> Male <br />
<input type="radio" name="sex" value="female"> Female <br />
<hr>
<p>In your case:</p>
<input type="radio" name="person" value="m"/>MS Dhoni <br />
<input type="radio" name="person" value="v"/>Virat Kohli<br />
<input type="radio" name="person" value="s"/>Sachin Tendulkar <br/>
Upvotes: 1
Reputation: 943571
Radio buttons allow you to select one item from a radio group. This isn't the same as on the page because you can have multiple radio groups in a single form.
The name
attribute is used to distinguish between groups.
All your radio buttons have different names
so they are members of different groups.
Give them all the same name
and use the value
attribute to distinguish between them.
Add <label>
elements to associate the text that describes the radio button with the correct button.
<label><input type="radio" name="something" value="m"> MS Dhoni</label><br>
<label><input type="radio" name="something" value="v"> Virat Kohli</label><br>
<label><input type="radio" name="something" value="s"> Sachin Tendulkar</label><br>
Upvotes: 3
Reputation: 1544
Try like this. This is how we have to use radio button.
<input type="radio" name="player"/>MS Dhoni <br />
<input type="radio" name="player" />Virat Kohli<br />
<input type="radio" name="player"/> Sachin Tendulkar <br/>
Upvotes: 0