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%"> </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">
</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:
<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>