Click to See Complete Forum and Search --> : form validation driving me bonkers!
Hi!
I'm trying to validate a simple guest book.
It must:
a) produce an alert when the email address is invalid;
b) produce an alert when a catagory of visitor is not selected;
c) produce an alert box informing them of the info that they have put in.
I can only get any 2 of the following working.. never all three!
Any ideas?
the script and html page are attached
Thanks
luds
khalidali63
04-29-2003, 05:37 PM
Check this form out.It will help you understand the whole concept
http://68.145.35.86/skills/javascripts/UltimateFormValidator.html
Nedals
04-29-2003, 06:09 PM
There are a few errors in your javascript. Here is a working version. PLEASE look it over and understand what I did.
function submitIt(feedbackform) {
//if (document.feedbackform.catagory != 0) { ... deleted
//test 1
var catagorytype = "";
for (i = 0; i < document.feedbackform.catagory.length; i++) {
// removed ';' after ..checked);
if (document.feedbackform.catagory[i].checked) { catagorytype = document.feedbackform.catagory[i].value; }
}
if (!catagorytype) {
alert("Please enter a catagory!");
return false
}
//test 2 - removed extra '{ }'
if (re.test(feedbackform.emailaddress.value)) {
alert("Your Name: "+ feedbackform.yourname.value + "\nYour email: "+ feedbackform.emailaddress.value + "\nYour Catagory: "+ catagorytype + "\nYour Comments: "+ feedbackform.comments.value)
return true
} else { // else was missing
alert("Invalid email address")
feedbackform.emailaddress.focus()
feedbackform.emailaddress.select()
return false
}
}
many many thanks, Khalidali63 and Nedals!
Not only do I have a script that works properly now... but I understand more javascript too!
Thank you for your time and patience!
luds :)