Google Answers Logo
View Question
 
Q: For Secret901 - further form validation ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: For Secret901 - further form validation
Category: Computers > Programming
Asked by: horseradish-ga
List Price: $5.00
Posted: 15 Nov 2003 09:17 PST
Expires: 15 Dec 2003 09:17 PST
Question ID: 276152
Thanks for your help with the previous form validation script. I have
now extended the form and tried to amend the script myself but have
come up against an error I can't see my way around.

Currently it allows the form to be validated even when only the top
half (up to 'address') is filled in. I can't understand why this is
happening.

I'd be really grateful if you could check it over and make sure it all
works as it should. As it's simply repeating the same validation
checks again and again I can't see why there's a problem!

http://www.redjam.com/testform.html

Thank you very much
Answer  
Subject: Re: For Secret901 - further form validation
Answered By: secret901-ga on 15 Nov 2003 17:10 PST
Rated:5 out of 5 stars
 
Hi again horseradish!

Thank you for personally requesting for me again.  I'm sorry I
couldn't get back to you sooner, but I was experiencing some
connection problem.
I have looked over your code, and discovered some common errors when
copying and pasting code:
1) You forgot to rename the fields containing the weights for the male
and female into weightf and weightm
2) In the script, you forgot to change the part about how they found
your site so that it refers to discover.

I have made the necessary changes below, and the new code appears to
work.  If anything seems to still not work correctly, please let me
know.  Furthermore, if the line breaks is causing problems, let me
know and I can put them into a zip file for you to download.

Thanks,
secret901-ga

HTML CODE BELOW
----------------------------------------------

<html>
<head>
	<title>Untitled</title>
</head>
<body>
 <script language = "Javascript"> 
 function validate(aForm) { 
  //either couple or single must be checked 
  if (!aForm.who[0].checked  && !aForm.who[1].checked) { 
   alert("Please choose either couple or single woman."); 
   return false; 
  } 
  //one of the locations must be checked 
  else if (!aForm.mailsubj[0].checked && !aForm.mailsubj[1].checked &&
!aForm.mailsubj[2].checked && !aForm.mailsubj[3].

checked) {
   alert("Please select a location, or check 'Other'"); 
   return false; 
  } 
  //both names filled in if couple is checked 
  else if(aForm.who[0].checked && (aForm.namem.value == "" ||
aForm.namef.value == "")) {
   alert("Please fill in both names if you're registering as a couple.");
   return false; 
  } 

  //both ages, heights and weights filled in if couple is checked 
  else if(aForm.who[0].checked && (aForm.agef.value == "" ||
aForm.heightf.value == "" || aForm.weightf.value == "" || aForm

.agem.value == "" || aForm.heightm.value == "" || aForm.weightm.value == "")) { 
   alert("Please enter the age, weight and height of both applicants.");
   return false; 
  } 
   
  //female name filled in if single is checked 
  else if(aForm.who[1].checked && aForm.namef.value == "") { 
   alert("Please fill in the female's name if you're registering as a single.");
   return false; 
  } 
         
  //female age, height and weight filled in if single is checked 
  else if(aForm.who[1].checked && (aForm.agef.value == "" ||
aForm.heightf.value == "" || aForm.weightf.value == "")) {
   alert("Please enter your age, weight and height.");
   return false; 
  }  
  
  //Address, post code and email address should all have text in.  
  else if(aForm.address.value == "" || aForm.country.value == "" ||
aForm.postalcode.value == "" || aForm.fname.value == "")

{
   alert("Please fill in all information for address, country, post
code, and email address.");
   return false; 
  } 
  
//validate email address 
  else if(aForm.fname.value.search(/\b[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\.[A-Za-z0-9._%-]{2,4}\b/)
== -1) {
   alert("Please use a valid email address."); 
   return false; 
  } 
  
  //prompt user if expertise is blank 
  else if(aForm.expertise.value == "") { 
   alert("Please describe your level of expertise.");
    return false; 
   } 
        
  //prompt user if comment is blank 
  else if(aForm.sentence.value == "") { 
   alert("Please tell us a little about yourselves.");
    return false; 
   } 

  //prompt user if how they heard of us is blank 
  else if(aForm.discover.value == "") { 
   alert("We'd really appreciate learning how you heard about us, thanks!");
    return false; 
   } 

  //pic upload prompt if couple is checked 
  else if(aForm.who[1].checked && (aForm.FILE1.value == "" &&
aForm.FILE2.value == "")) {
   alert("You must send at least one picture.");
   return false; 
  } 
     
  //pic upload prompt if single is checked 
  else if(aForm.who[0].checked && (aForm.FILE1.value == "" &&
aForm.FILE2.value == "")) {
   alert("You must send a picture of yourself.");
   return false; 
  } 
      
  return true; 
 } 
 </script> 
 
 
<TABLE class=body cellSpacing=0 cellPadding=0 width=415 border=0>

	<TR>
	<TD>
	<form action="http://www.redjam.com/cgi-bin/mailer.cgi?send_it"
enctype="multipart/form-data" method="post" onsubmit

="return validate(this);"><BR>
	<input type="Hidden" name="id" value="1068906731">
	<INPUT class=chk1 type=radio align=middle value=Couple name=who>Couple<BR>
	<INPUT class=chk1 type=radio align=middle value=Single name=who>Single
	<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B>for:</B></P><INPUT
class=chk1 type=radio align=middle value=LONDON name=

mailsubj>London <BR><INPUT class=chk1 type=radio align=middle
value=MANCHESTER name=mailsubj>Manchester <BR><INPUT class=chk1

type=radio align=middle value="LONDON AND MANCHESTER"
name=mailsubj>London and Manchester
	<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B>OR</B></P><INPUT class=chk1
type=radio align=middle value=OTHER name=

mailsubj>Other
	<P>
	<TABLE class=body cellSpacing=5 cellPadding=0 width=415 border=0>
		<TR vAlign=bottom>
			<TD class=forms>Male name:</TD>
			<TD><INPUT class=formbox name=namem></TD>
			<TD class=forms>Female name:</TD>
			<TD><INPUT class=formbox name=namef></TD></TR>
		<TR vAlign=bottom>
			<TD class=forms>Male age:</TD>
			<TD><INPUT class=formbox name=agem></TD>
			<TD class=forms>Female age:</TD>
			<TD><INPUT class=formbox name=agef></TD></TR>
		<TR vAlign=bottom>
			<TD class=forms>Male height:</TD>
			<TD><INPUT class=formbox name=heightm></TD>
			<TD class=forms>Female height:</TD>
			<TD><INPUT class=formbox name=heightf></TD></TR>
		<TR vAlign=bottom>
			<TD class=forms>Male weight:</TD>
			<TD><INPUT class=formbox name=weightm></TD>
			<TD class=forms>Female weight:</TD>
			<TD><INPUT class=formbox name=weightf></TD></TR>
		<TR vAlign=bottom>
			<TD class=forms>Residential address:</TD>
			<TD colSpan=3><INPUT class=formbox2 name=address></TD></TR>
		<TR vAlign=bottom>
			<TD class=forms>Country:</TD>
			<TD><INPUT class=formbox name=country></TD>
			<TD class=forms>Post code:</TD>
			<TD><INPUT class=formbox name=postalcode></TD></TR>
		<TR vAlign=bottom>
			<TD class=forms>Email address:</TD>
			<TD colspan=3><INPUT class=formbox2 name=fname></TD></TR>
		<TR vAlign=bottom>
			<TD class=forms>Level of expertise:</TD>
			<TD colspan=3><INPUT class=formbox2 name=expertise></TD></TR>
		<TR vAlign=bottom>
			<TD class=forms>A little information about yourselves:</TD>
			<TD class=body colSpan=3><TEXTAREA class=formbox2 name=sentence
rows=3 cols=23></TEXTAREA></TD></TR>
		<TR vAlign=bottom>
			<TD class=forms>How did you discover us?</TD>
			<TD colspan=3><INPUT class=formbox2 name=discover></TD></TR>			
		<TR vAlign=bottom>
			<TD class=forms>His picture:</TD>
			<TD class=body colSpan=3><input type="File" class=formbox2
name="FILE1"></TD></TR>
		<TR vAlign=bottom>
			<TD class=forms>Her picture:</TD>
			<TD class=body colSpan=3><input type="File" class=formbox2
name="FILE2"></TD></TR>
		<TR><TD align=right colSpan=4><INPUT class=submit type=submit
value="SEND APPLICATION &raquo;" name=submit><

/form></TD></TR>
	</TABLE>
	</TD></TR>
</TABLE>

</body>
</html>

---------------------------------------------------------
HTML CODE ENDS

Clarification of Answer by secret901-ga on 15 Nov 2003 17:15 PST
The last sentence should be "...if the line breaks ARE causing problems..."
Please excuse me for the grammatical mistake.

secret901-ga
horseradish-ga rated this answer:5 out of 5 stars
Excellent full answer once again from this great researcher

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy