i have two radio button for selecting gender. and used below JS but if 'female' button is selected it takes it but if 'male' is selected it showing that none is selected.
var r = document.getElementsByName("sex")
var sex= -1;
for(var i=0; i <= r.length; i++)
{
if(r[i].checked)
{
sex = i;
}
if (sex == -1)
{
alert("please select gender");
return false;
}
}
i have taken two div for two radio with same name for both radio. so here is my html to check if problem is there,
<div style="margin-top:17px; width:92px;float:left;">
<input id="female" class="radio" type="radio" name="sex" value="female">Female</input>
</div>
<div style="margin-top:17px; width:92px;float:left; margin-bottom:17px;">
<input class="radio" id="male" type="radio" name="sex" value="male">Male</input>
</div>