Reputation: 372
I'm stuck, I'm not sure which way I should use to solve this. I have four radio buttons
<label class="btn btn-default active">
<input type="radio" name="_hsync_rasa" id="0" autocomplete="off" checked> Bijelac
</label>
<label class="btn btn-default">
<input type="radio" name="_hsync_rasa" id="1" autocomplete="off"> Crnac
</label>
<label class="btn btn-default">
<input type="radio" name="_hsync_rasa" id="2" autocomplete="off"> Hispanac
</label>
<label class="btn btn-default">
<input type="radio" name="_hsync_rasa" id="3" autocomplete="off"> Azijac
</label>
So, my question is how to uncheck and check other button? I did code but it doesn't work. Only problem is because I use 0 and 1 for sex(male-female), input name is different, it's not _hsync_rasa.
function _hsync_prilagodi_rasu(_trenutna, _nova)
{
$("input[name=_hsync_rasa]:radio:id:#"+ _nova +"").attr('checked', 'checked');
}
I added two params _trenutna(it means current) and _nova(it means new) becase I'm not sure will current radio button uncheck when jQuery check new radio button.
Upvotes: 0
Views: 898
Reputation: 11856
You don't need to uncheck the other radiobutton first. There can only be one radiobutton (with the same name of course) be checked. Checking another one will automatically uncheck the previous one.
So this is enough
$('[name=_hsync_rasa]#3').prop('checked', true);
Or to clear all selected items
$('[name=_hsync_rasa]').prop('checked', false);
Upvotes: 1