Results 1 to 3 of 3
Thread: trouble validating 2 conditions
- 08-23-2010, 06:05 PM #1
Member
- Join Date
- Aug 2010
- Posts
- 1
- Rep Power
- 0
trouble validating 2 conditions
Having trouble validating a form.
What I want to accomplish is if two conditions contain data then display an alert message.
If condition1 = "something" AND "name" or "last" or "homefone" or "email" also = "something" then display alert (condition1 has to be null if any other 4 contain data or if the other 4 contains data then condition1 can not.)
When condition1 is null and others contain data it works fine (no alert), when condition1 and the others contain data the alert is displayed.
What happens is when condition1 is unpicked (null) the alert message is still displayed
An easier way to describe it:
A=condition1
B=name,last,homefone,email
"A" has to be null if any items in "B" contains data
or
"B" has to be null if "A" contains data
is there an easier way to write the validating code??
thank you
XML Code:<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>New Page 2</title> </head> <body> <!-------------Alert to enter all info------------------> <SCRIPT language="JavaScript"> <!-- Hide from non java browsers function SendForm(form) { var stringVar = ""; var flag = ""; if (( form.condition1.value != "") && ( form.name.value != "" ) || ( form.last.value != "" ) || ( form.homefone.value != "" ) || ( form.email.value != "" )) { stringVar += "You can not request both maintenance and violations.\n"; } if (form.name.value == "") { stringVar += "Your first name is required.\n"; } if (form.last.value =="") { stringVar += "Your Last name is required.\n"; } if (form.homefone.value == "") { stringVar += "A contact number is required.\n"; } if (form.email.value == "") { stringVar += "An email address is required.\n"; } if (form.terms.checked) { } else { stringVar += "You must accept Terms and Conditions.\n"; } if (stringVar.length){ alert(stringVar); return false; } else { return true; } } //--> </SCRIPT> <!---------------------------------------------> <!---start of form mailer---> <FORM onSubmit="return SendForm(this)" action="http://www.anyplace.com/form-mailer/form_submit.php" method="POST"> <tr><td width=140>First Name:<span style="color:cc0000;">*</span></td> <td width=240><INPUT type="text" name="name" onFocus="this.value=''" style="border-color:#7C7C7C;border-width:1px;border-style:Solid;width:180px;" /> <tr><td colspan=2></td></tr> <tr><td width=140><p>Last Name:<span style="color:cc0000;">*</span></td> <td width=240><input type="text" name="last" onFocus="this.value=''" style="border-color:#7C7C7C;border-width:1px;border-style:Solid;width:180px;" /> <tr><td colspan=2></td></tr> <tr><td width=140></p> <p>Home Phone:<span style="color:cc0000;">*</span><br /> <span style="font-size:8pt;color:#4c5d63;">(555-555-1212)</span></td> <td valign=top><input type="text" name="homefone" onFocus="this.value=''" style="border-color:#7C7C7C;border-width:1px;border-style:Solid;width:180px;" /> </td></tr> <tr><td colspan=2></td></tr> </p> <p> <tr><td width=140>E-mail Address:<span style="color:cc0000;">*</span></td> <td><input type="text" name="email" onFocus="this.value=''" style="border-color:#7C7C7C;border-width:1px;border-style:Solid;width:180px;" /> </td></tr> <tr><td colspan=2></td></tr> <tr><td width=140><tr><td colspan=2></td></tr> </p> <p> <tr><td width=140>CONDITION1:</td> <td><select name="condition1" id="condition1"> <option value=""></option> <option value="Pigeons">Pigeons</option> <option value="Spiders">Spiders</option> <option value="Wasps">Wasps</option> <option value="Yellow Jackets">Yellow Jackets</option> </select></td></tr> </tr> <tr><td colspan=2></td></tr> </p> <p> <tr><td colspan=2><label for="offerCheckBox"><FONT COLOR="blue">Do you agree to the Terms and Conditions?</font> <input type="checkbox" name="terms" value="Yes"> Yes<span style="color:cc0000;">*</span> <br> By requesting that this work be completed, the tenant<br> acknowledges that if the repair is found to be due to misuse or the<br> repair is not the responsibility of the landlord as specified in the<br> lease, the tenant may be responsible for payment of the repair per<br> the lease agreement. </label></td> </tr> <tr><td colspan=2><img src="spacer.gif" height=5 width=0 /></td></tr> <tr><td colspan=2></p> <p></td></tr> <tr><td colspan=2 align=center><INPUT TYPE=SUBMIT VALUE="submit"> </td></tr> </table></div></div> </p> </body> </html>
- 08-23-2010, 06:17 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Erm, this is a Java forum, not a Javascript forum.
kind regards,
Jos
-
Similar Threads
-
Reading Text File with Certain Conditions
By balaji csc in forum New To JavaReplies: 1Last Post: 11-10-2009, 11:38 AM -
[SOLVED] Change text colour on conditions in netbeans
By dbashby in forum New To JavaReplies: 0Last Post: 03-26-2009, 01:23 AM -
Asking for a username with conditions
By ScentOfAWookie in forum New To JavaReplies: 2Last Post: 03-20-2009, 05:53 AM -
[SOLVED] if else conditions not working. T_T
By uncanny in forum Advanced JavaReplies: 4Last Post: 10-17-2008, 05:44 AM


LinkBack URL
About LinkBacks


Bookmarks