0

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>
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by AngelicOne
0

Yeah you're right. But the problem lies at line 9. It should be less than only, not less than or equal.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.