Results 1 to 3 of 3
  1. #1
    cottoneye1256 is offline Member
    Join Date
    Aug 2010
    Posts
    1
    Rep Power
    0

    Default 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>
    &nbsp;<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>
    &nbsp;<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>&nbsp;<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>
    &nbsp;<tr><td width=140><tr><td colspan=2></td></tr>&nbsp;</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>&nbsp;<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>
    &nbsp;<tr><td colspan=2 align=center><INPUT TYPE=SUBMIT VALUE="submit">
    </td></tr>
    </table></div></div>
    
    
    
    </p>
    
    
    
    </body>
    
    </html>

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,731
    Blog Entries
    7
    Rep Power
    21

    Default

    Erm, this is a Java forum, not a Javascript forum.

    kind regards,

    Jos

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Reading Text File with Certain Conditions
    By balaji csc in forum New To Java
    Replies: 1
    Last Post: 11-10-2009, 12:38 PM
  2. Replies: 0
    Last Post: 03-26-2009, 02:23 AM
  3. Asking for a username with conditions
    By ScentOfAWookie in forum New To Java
    Replies: 2
    Last Post: 03-20-2009, 06:53 AM
  4. [SOLVED] if else conditions not working. T_T
    By uncanny in forum Advanced Java
    Replies: 4
    Last Post: 10-17-2008, 06:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •