PDA

View Full Version : Form Validation Problem


Jobu
02-24-2005, 12:03 AM
Hey guys. I'm trying to do some simple form entry validation. The one that is stumping me is a text entry field. Basically, if the user does not enter some text into the field, I want an alert to say "Please answer all questions."

Here is the form element:

<input type="text" name="city" value="<type answer here>" />

Here is the javascript:

if (document.quiz.city=="<type answer here>") {
alert('Please answer all questions.');
return false;
}


The form name is "quiz." The if statement is part of a fuction "validate" which is called with onSubmit and onClick. The more difficult elements of the validation are working (i.e. checkboxes and radio questions), but this one will not work. If I leave the "<type answere here>" intact in the form, and hit submit, I should get the alert, but I don't. Any suggestions? Thanks.

Brandoe85
02-24-2005, 12:46 AM
Try:

if (document.quiz.city.value=="<type answer here>") {
alert('Please answer all questions.');
return false;
}

Jobu
02-24-2005, 07:02 AM
Thanks :thumbsup: