Hi,
I have a script that is supposed to check if one of the radio buttons
in a form is checked and either display an "alert" or go to another
page.
<html>
<head>
<title></title>
</head>
<body>
<script type="text/Javascript">
function getRadioButtonChecked (radio){
for (var i = 0; i < radio.length; i++){
if (radio[i].checked){
return true;
}
}
return false;
}
</script>
<form name="myform" method="post" action="somefile.php">
<input id="req_any" name="req_any" type="radio" value="AVM-MC1"
onClick="if (this.checked)
document.getElementById('qty_AVM-MC1').value='1'; else
document.getElementById('qty_AVM-MC1').value='0'">Product1<br />
<input type="hidden" id="qty_AVM-MC1" name="qty_AVM-MC1" value="0">
<input id="req_any" name="req_any" type="radio" value="AVM-HTC1"
onClick="if (this.checked)
document.getElementById('qty_AVM-HTC1').value='1'; else
document.getElementById('qty_AVM-HTC1').value='0'">Product2<br />
<input type="hidden" id="qty_AVM-HTC1" name="qty_AVM-HTC1" value="0">
<br />
<span style="margin-left:40%;">
<input name="OK" type="submit" value="Add" onClick="if
(getRadioButtonChecked(document.getElementById('re q_any'))){document.location.href='anotherfile.php' ;
return true;} else{ alert('You must select one of the required
options.'); return false;}">
</span>
<span style="margin-left:50;">
<input name="Cancel" type="button" value="Cancel"
onClick="document.location.href='cancel.php'">
</span>
</form>
</body>
When I click on the "Add" button, I get a javascript error saying
"radio is not defined". What am I doing wrong?