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

    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" has to be null if any items in "B" contains data
    "B" has to be null if "A" contains data

    is there an easier way to write the validating code??

    thank you

    XML Code:
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>New Page 2</title>
    <!-------------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.last.value != "" ) ||  ( form.homefone.value != "" ) ||  ( != "" ))
    			stringVar += "You can not request both maintenance and violations.\n";
    	} if ( == "") {
    	        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 ( == "") {
    	        stringVar += "An email address is required.\n";
        } if (form.terms.checked) {
    		else 	{
    			stringVar += "You must accept Terms and Conditions.\n";
    	if (stringVar.length){
    		return false;
    	} else {
    		return true;
    <!---start of form mailer--->
    <FORM onSubmit="return SendForm(this)" action="" 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;" />
    <tr><td colspan=2></td></tr>
    <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;" />
    <tr><td colspan=2></td></tr>
    &nbsp;<tr><td width=140><tr><td colspan=2></td></tr>&nbsp;</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>
    <tr><td colspan=2></td></tr>
    <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>
    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.
    <tr><td colspan=2><img src="spacer.gif" height=5 width=0 /></td></tr>
    <tr><td colspan=2></p>
    &nbsp;<tr><td colspan=2 align=center><INPUT TYPE=SUBMIT VALUE="submit">

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power


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

    kind regards,


  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

Similar Threads

  1. Reading Text File with Certain Conditions
    By balaji csc in forum New To Java
    Replies: 1
    Last Post: 11-10-2009, 11:38 AM
  2. Replies: 0
    Last Post: 03-26-2009, 01:23 AM
  3. Asking for a username with conditions
    By ScentOfAWookie in forum New To Java
    Replies: 2
    Last Post: 03-20-2009, 05:53 AM
  4. [SOLVED] if else conditions not working. T_T
    By uncanny in forum Advanced Java
    Replies: 4
    Last Post: 10-17-2008, 05: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