Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't select between radio buttons in HTML?

Tags:

html

I have the following form code but I cannot select the sell radio in IE and I can select both radios at once in Google Chrome.

<form method="post" action="dothemath.php" style="width: 403px" class="style1">
<input type="radio" id="rdobuy" style="width: 20px; height: 21px;" checked="checked"/>
<label>Buy</label>
<input type="radio" id="rdosell" style="width: 20px; height: 21px;"/>
<label >Sell</label>
</form>

Is there any thing I am missing...?

like image 240
medo ampir Avatar asked Nov 27 '11 19:11

medo ampir


2 Answers

Your radio buttons don't have name attribute. They need them for two reasons.

  1. Having the same name groups a set of radio buttons into a single radio group
  2. The name is used to generate the form data to be submitted to the server

You also need a value to say what the submitted data is going to be.

As an aside, your <label>s are useless as they aren't associated with any controls. They need a for attribute with the same value as the id of the control they are to be associated with.

<form method="post" action="dothemath.php">

    <input type="radio" id="rdobuy" name="foo" value="buy" checked="checked"/>
    <label for="rdobuy">Buy</label>

    <input type="radio" name="foo" value="sell" id="rdosell" />
    <label for="rdosell">Sell</label>

</form>
like image 131
Quentin Avatar answered Oct 11 '22 04:10

Quentin


You should add a name attribute and the names should be same for both radios.

like image 25
adyusuf Avatar answered Oct 11 '22 03:10

adyusuf