SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
-
Sep 14, 2006, 22:56 #1
- Join Date
- Dec 2001
- Location
- Vancouver, Canada
- Posts
- 352
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The form won't validate, can someone spot the mistake?
The site is not yet live, so I added the codes on one of my website: http://www.visual-directory.com/contact-us-test.php
Here is the code to make it easy on you:
HTML Code:<script> function validateIt(theForm) { //InquiryForSelf if(theForm.InquiryForSelf.selectedIndex==0) { alert("Please tell us whether this request is for you"); theForm.InquiryForSelf.focus(); return (false); } //YourFirstName if(theForm.YourFirstName.selectedIndex==0) { alert("Only your first name is required"); theForm.YourFirstName.focus(); return (false); } //Phone if(theForm.Phone.selectedIndex==0) { alert("Your Telephone # is kept Private but is required"); theForm.Phone.focus(); return (false); } //TimeToCall if(theForm.TimeToCall.selectedIndex==0) { alert("When is the best time to call?"); theForm.TimeToCall.focus(); return (false); } //email if(document.tafform.from_email.value=="") { alert("Enter email."); theForm.from_email.focus(); return (false); } else { var str=document.tafform.from_email.value; var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i if (filter.test(str)) return true; else { alert("Please input a valid email address!") return false; } } return (true); }//end function //DescribeSituation if(theForm.DescribeSituation.selectedIndex==0) { alert("Please provide us with a brief overview of the situation"); theForm.DescribeSituation.focus(); return (false); } } </script>
HTML Code:<FORM action="http://www.example.com/cgi-bin/tafform/sendit.cgi" method="POST" name="tafform" ID="tafform" onSubmit="return validateIt(this)">
-
Sep 15, 2006, 00:01 #2
I suspect you have a misplaced curly brace, indent your code so you can see everything aligned properly. Also you are checking the selectedIndex on some fields that do not have that property.
-
Sep 15, 2006, 00:04 #3
Yeah, that whole bit under //DescribeSituation is not contained within a function. Also (I might cop some flack for this), learn to write code with only a single exit point, it's easier to test and validate.
Bookmarks