If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 1 of 1
  1. #1
    Junior Member
    Join Date
    Apr 2005
    Member #
    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

    HTML 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">


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
All times are GMT -6. The time now is 02:44 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: