[thelist] JavaScript form validation - do all radio groups have a selection checked?
Canfield, Joel
JCanfield at PacAdvantage.org
Mon Aug 1 11:45:07 CDT 2005
Can you see why this does absolutely nothing? The alert at the beginning
of the function doesn't even happen, although if I remove everything
*except* the alert, it does.
In the form page:
<script type="text/javascript" src="isValid.js"></script>
and later
<form name="foodForm" method="POST" action="foodborne_answers.asp"
onSubmit="return isValid(this);">
and this for the JavaScript:
function isValid(form)
{
alert("in the script")
myWholeFormArray = document.theForm.elements
for (a = 0; a < myArray.length; a++
{
myArray = document.theForm.elements[a];
{
if document.theForm.elements[a].type == "radio"
myChecked = false;
for (b = 0; b < myArray.length; b++)
{
if (myArray[b].checked)
{
myChecked = true;
}
}
}
if (myChecked == false)
{
alert("Please select an answer for " +
elements[a].name)
for (b = 0; b < myArray.length; b++)
{
myArray[b].style.backgroundColor='red';
}
return false
}
}
alert("out of the script")
return true
}
Thanks.
joel
More information about the thelist
mailing list