> Hi Lee,
> thanks a lot for the info.
> The page is generated dynamically through a php file. I made the
> changes you suggested and thsi the resuting page, which seems to
> satisfy your suggestions. Thejavascript console still shows the same
> error message: "error: radio is not defined".
The error message is correct.
> function getRadioButtonChecked (radio){
> for (var i = 0; i < radio.length; i++){
[quoted text clipped - 6 lines]
> return false;
> }
You have an input element with the value of "req_any" for the name
attribute. When the form gets submitted, you pass a _string_ to your
function getRadioButtonChecked. However, in your function, you're
trying to use "radio" as an object, when in reality you passed to it a
string. Try modifying your code like so:
javascript:
function getRadioButtonChecked(myForm)
{
for(var i = 0; i < myForm.elements["req_any"].length; i++)
{
if(myForm.elements["req_any"][i].checked)
{
alert("radio " + i + " is checked");
return true;
}
}
alert("You must select one of the required options.");
return false;
}
html:
<form [...add form attributes...] onsubmit = "return
getRadioButtonChecked(this)">
[...add your form controls...]
</form>
Xerxes - 28 Feb 2006 05:39 GMT
Thanks alot for your help. Your suggestion worked.
Xerxes said:
>Hi Lee,
>thanks a lot for the info.
[quoted text clipped - 23 lines]
><form name="error_form" method="post" action="add_additional.php"
>onsubmit="return getRadioButtonChecked('req_any')">
Remove the quotes from around req_any.
You want to pass a reference to the form element req_any,
not the name of the element.