Form verification help
Hello,
Can anyone tell me how to verify input from a form when using the "select option"? For example, if I have something like the following, and I want to use the function valForm to check to ensure that not every selection was 0 (zero), how would I do it? I've tried a number of things, including:
if(document.orderForm.first.value=="0" &&
document.orderForm.second.value=="0"){
alert("error message");
return false;
}
but nothing is working. Thanks!
Bob
************************
0
1 2
3 4
0
1 2
3 4
Mark Hensler posted this at 22:02 — 17th August 2000.
He has: 4,048 posts
Joined: Aug 2000
do you need to include 'return true'? Like this:
if(document.orderForm.first.value=="0" &&
document.orderForm.second.value=="0"){
alert("error message");
return false;
}
else{
return true;
}
Mark Hensler
If there is no answer on Google, then there is no question.
Vincent Puglia posted this at 15:25 — 18th August 2000.
They have: 634 posts
Joined: Dec 1999
Hi,
You could loop through the form and use the following:
if (elements[i].type == 'select-one')
if (elements[i].options[0].selected)
{
eval(elements[i].options[0].value)
isOK = false;
}
where options[0].value is an alert, and isOK is a boolean variable that decides whether to submit the form or not. The above was cut from the "Validating Forms" script/tutorial at my site.
Vinny
Where the world once stood
the blades of grass cut me still
Bob posted this at 15:26 — 18th August 2000.
They have: 117 posts
Joined: Feb 2000
Max,
Thanks for the reply. I was able to get it to work. No, you don't need to use the "return true" statement. The following worked:
if(document.orderForm.first.selectedIndex==0 && document.orderForm.second.selectedIndex==0){
alert("error message");
return false;
}
Bob
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.