[thelist] JavaScript form validation - do all radio groups have a selection checked?

Peter Brunone (EasyListBox.com) peter at easylistbox.com
Mon Aug 1 12:07:02 CDT 2005


   What happens if you add a semicolon after your alert statement (and other places where you have a line break inside functions?

 From: "Canfield, Joel" JCanfield at PacAdvantage.org

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:

and later

 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