Reputation: 213
I'm trying to have a number of radio buttons but I want only 1 to be selected at a time. If one is selected then the previous should get deselected.
Currently all radio buttons can be selected and they don't deselect on change.
How do I fix this?
<div class="container">
<h2 class="form-signin-heading">Existing Users</h2>
<div class="input-group">
<span class="input-group-addon">
<input type="radio" aria-label="...">
</span>
<label class="form-control" aria-label="...">User-1</label>
</div>
<div class="input-group">
<span class="input-group-addon">
<input type="radio" aria-label="...">
</span>
<label class="form-control" aria-label="...">User-2</label>
</div>
</div>
JSFiddle: https://jsfiddle.net/a8Lteg1p/
Upvotes: 1
Views: 106
Reputation: 1544
<div class="container">
<h2 class="form-signin-heading">Existing Users</h2>
<div class="input-group">
<span class="input-group-addon">
<input type="radio" name="my-radio-group" aria-label="...">
</span>
<label class="form-control" aria-label="...">User-1</label>
</div>
<div class="input-group">
<span class="input-group-addon">
<input type="radio" name="my-radio-group" aria-label="...">
</span>
<label class="form-control" aria-label="...">User-2</label>
</div>
</div>
Add Name attr to your radio button. There is no unique about the radio buttons you have entered.
Upvotes: 2
Reputation: 3202
use common name attribute value for all the checkboxes you want.
name='grouped' value can be anything.just used `grouped` for your reference.
see the working fiddle here
Upvotes: 0
Reputation: 1141
Please add name of radio button like this
<div class="container">
<h2 class="form-signin-heading">Existing Users</h2>
<div class="input-group">
<span class="input-group-addon">
<input type="radio" name="radio" aria-label="...">
</span>
<label class="form-control" aria-label="...">User-1</label>
</div>
<div class="input-group">
<span class="input-group-addon">
<input type="radio" name="radio" aria-label="...">
</span>
<label class="form-control" aria-label="...">User-2</label>
</div>
</div>
Upvotes: 2