I know I am doing this right but it just doesn't work. The condition for radiobutton that if it's not checked then an alert should display. But it won't work!
<script>
function valid()
{
var element = document.forms["form"]["gender"];
var check = false;
for(i=0;i<=element.length;i++)
{
if(element[i].checked)
{
check = true;
break;
}
}
if(check == false)
{
alert("FALSE")
}
else
{
alert("TRUE");
}
}
</script>
<form name="form" onsubmit="valid()">
<input type="radio" name="gender" value="Male"/>Male<br/>
<input type="radio" name="gender" value="Male"/>Female<br/>
<input type="submit" name="submit" value="Submit"/>
</form>