Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    trg
    trg is offline
    New Coder
    Join Date
    Jun 2005
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Validating multiple drop-downs for content

    I have a form and have made some of the text fields required. Now I want to make two of my drop-down fields (selects) also required. I kind of figured out how to make one of them required, but can't get both to work... Here is my coding.. Any Advise?? THANKS!
    Code:
    <script>
    <!--
    function checkDropDown(Category) {
      if(document.getElementById(Category).value != 'none') {
       return true;
      }
      else {
       alert('Please select a Category from the drop down');
        return false;
       }
     }
    
    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    }
    
    function MM_validateForm() { //v4.0
      var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
      for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
        if (val) { nm=val.name; if ((val=val.value)!="") {
          if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
            if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
          } else if (test!='R') { num = parseFloat(val);
            if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
            if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
              min=test.substring(8,p); max=test.substring(p+1);
              if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
        } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
      } if (errors) alert('The following error(s) occurred:\n'+errors);
      document.MM_returnValue = (errors == '');
    }
    //-->
    </script>
    Here's the form:
    Code:
    <form name="ciwqsform" method="POST" action="../cgi-bin/FormMail.cgi" onsubmit='return checkDropDown("Category");'><br>
    			
    		<input name="recipient" type="hidden" value="tgomez@waterboards.ca.gov">
    							<table width="100%"  border="0" cellspacing="0" cellpadding="4">
                                  
                                  <tr>
                                    <td colspan="2"><hr></td>
                                    </tr>
                                  <tr class="header">
                                    <td width="50%"><font color="#000000">
    								<font color="#FF0000">*</font> Name: 
                                        <input type="text" name="Name" size="30">
                                    </font></td>
                                    <td width="50%">&nbsp;</td>
                                  </tr>
                                  <tr class="header">
                                    <td colspan="2"><font color="#000000">
    								<font color="#FF0000">*</font> Phone number: 
    								    <input type="text" name="Phone" SIZE="15">
    								</font><font color="#000000">
    							&nbsp;&nbsp;</font></td>
                                    </tr>
                                  <tr class="header">
                                    <td colspan="2"><hr color="#000066"></td>
                                    </tr>
                                  <tr class="header">
                                    <td colspan="2"><font color="#FF0000">*</font><font color="#000000"> Category:&nbsp; 
    						<select name="Category" id="Category">
    						<option value="none" selected>Select a Category</option> 
                            <option value="BUG: feature not working as designed, system errors, performance">BUG: feature not working as designed, system errors, performance</option>
                            <option value="DATA: incorrect or missing values, migration isssues">DATA: incorrect or missing values, migration isssues</option>
    	                    <option value="DATABASE STRUCTURE">DATABASE STRUCTURE</option>
                          </select>
                                    </font></td></tr>
                                  
                                  <tr class="header">
                                    <td colspan="2"><font color="#FF0000">* </font><font color="#000000">Module:
                                        <select name="Module" id="Module">
                                  <option value="none" selected>Select a Module</option>
                                <option value="Inspections">Inspections</option>
                                 <option value="Places">Places</option>
                                            <option value="Parties">Parties</option>
                                  </select>
                                    </font></td>
                                  </tr>
                                  
                                  <tr class="header">
                                    <td colspan="2"><font color="#000000">Summary:
    				                    <input name="Summary" type="text" maxlength="50" size="70"> 
    								</font></td>
                                  </tr>
                                  <tr class="header">
                                    <td colspan="2"><font color="#FF0000">*</font><font color="#000000"> Description:<br>
                                        <textarea name="Description" cols=65 rows=5></textarea>
    </font></td>
                                  </tr>
                                </table>
    								                                <p> 
                                      <input type="submit" id='submit' onClick="MM_validateForm('Name','','R','Phone','','R','Description','','R');return document.MM_returnValue"  value="Submit" >
                                    </form>

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,518
    Thanks
    3
    Thanked 506 Times in 493 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    </head>
    
    <body>
    <form name="ciwqsform" method="POST" action="../cgi-bin/FormMail.cgi" onsubmit='return checkDropDown("Category");'>
     <input name="recipient" type="hidden" value="tgomez@waterboards.ca.gov">
     <table width="100%"  border="0" cellspacing="0" cellpadding="4">
      <tr>
       <td colspan="2"><hr></td>
      </tr>
      <tr class="header">
       <td width="50%"><font color="#000000">
       <font color="#FF0000">*</font> Name:
       <input class="zxcMustBeTxt" title="Name must be completed" type="text" name="Name" size="30">
       </font>
       </td>
      <td width="50%">&nbsp;</td>
      </tr>
      <tr class="header">
       <td colspan="2"><font color="#000000">
       <font color="#FF0000">*</font> Phone number:
       <input class="zxcMustBeNu" title="Phone number must be a number"  type="text" name="Phone" SIZE="15">
       </font><font color="#000000">
       &nbsp;&nbsp;</font>
      </td>
     </tr>
     <tr class="header">
      <td colspan="2"><hr color="#000066"></td>
      </tr>
      <tr class="header">
       <td colspan="2"><font color="#FF0000">*</font><font color="#000000"> Category:&nbsp;
       <select class="zxcMustBeTxt" title="Category must be selected" name="Category" id="Category">
       <option value="none" selected>Select a Category</option>
       <option value="BUG: feature not working as designed, system errors, performance">BUG: feature not working as designed, system errors, performance</option>
       <option value="DATA: incorrect or missing values, migration isssues">DATA: incorrect or missing values, migration isssues</option>
       <option value="DATABASE STRUCTURE">DATABASE STRUCTURE</option>
       </select>
       </font>
       </td>
      </tr>
      <tr class="header">
       <td colspan="2"><font color="#FF0000">* </font><font color="#000000">Module:
       <select class="zxcMustBeTxt" title="Module must be selected" name="Module" id="Module">
       <option value="none" selected>Select a Module</option>
       <option value="Inspections">Inspections</option>
       <option value="Places">Places</option>
       <option value="Parties">Parties</option>
       </select>
       </font>
       </td>
      </tr>
      <tr class="header">
       <td colspan="2"><font color="#000000">Summary:
       <input name="Summary" type="text" maxlength="50" size="70">
       </font>
       </td>
      </tr>
      <tr class="header">
       <td colspan="2"><font color="#FF0000">*</font><font color="#000000"> Description:<br>
       <textarea class="zxcMustBeTxt" title="Description must be Completed" name="Description" cols=65 rows=5></textarea>
       </font>
       </td>
      </tr>
     </table>
     <p>
     <input type="submit" id='submit' onClick=" return zxcvalidateForm(this.form);"  value="Submit" >
    </form>
    
    <script language="JavaScript" type="text/javascript">
    <!--
    
    
    
    function  zxcvalidateForm(zxc){
     var zxcfe=zxc.elements;
     var zxcmess='';
     for (var zxc0=0;zxc0<zxcfe.length;zxc0++){
      zxcfe[zxc0].style.backgroundColor='white'
      if (zxcfe[zxc0].className=='zxcMustBeTxt'&&(zxcfe[zxc0].value.length<1||zxcfe[zxc0].value=='none')){
       zxcfe[zxc0].style.backgroundColor='red';
       zxcmess+=zxcfe[zxc0].title+'\n';
      }
      if (zxcfe[zxc0].className=='zxcMustBeNu'&&(isNaN(zxcfe[zxc0].value)||zxcfe[zxc0].value=='')){
       zxcfe[zxc0].style.backgroundColor='red';
       zxcmess+=zxcfe[zxc0].title+'\n';
      }
     }
     if (zxcmess==''){
      return true;
     }
     alert(zxcmess);
     return false
    
    }
    
    //-->
    </script>
    </body>
    
    </html>


  •  

    Posting Permissions

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