Radio Button validation using Javascript in HTML 
This is very simple way to validate radio button through Javascript in HTML Form.



<script type="text/javascript">
function validate_form (str) {
valid = true;
if (
(document.frmSample.rdo1[0].checked == false )
&& ( document.frmSample.rdo1[1].checked == false ) )
{
alert ( "Please choose your option" );
valid = false;
}
else if( document.frmSample.rdo1[0].checked == true ) {
alert ( document.frmSample.rdo1[0].value );
valid=true;
}
else if( document.frmSample.rdo1[1].checked == true ) {
alert ( document.frmSample.rdo1[1].value );
valid=true;
}
}
</script>

***************************
<html>
<body>
<form name="frmSample" action="#" method="post" onSubmit="return validate_form();">
<input type="radio" name="rdo1" value="Male" />Male<br />
<input type="radio" name="rdo1" value="Female" />Female<br />
<input type="button" name="submit" value="Check" onClick="return validate_form();"/>
</form>
</body>
</html>


[ add comment ] ( 1 view )   |  permalink  |   ( 3 / 15 )

<<First <Back | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Next> Last>>