Hi everyone. I'm trying to get 2 drop down menus to each have something selected when the form is submitted. I'm using javascript for this, but I can't get it to work. Basically, if one is blank and the other one isn't, I want an error to pop up saying they have to fill in the one that is blank and vice versa. What am I doing wrong? Here's what I have for the javascript and on the form below. My 2 drop down names are Mfg_Spec_Prod_Approval_Initials and Mfg_Spec_Prod_Approval_Rev. Thanks for anyone's help!
Andy
<SCRIPT LANGUAGE="JavaScript">
function verify() {
var partNumber = '';
var ecoNumber = '';
var ProdInit;
var ProdInitValue='';
var ProdRev;
var ProdRevValue='';
var allArray = document.getElementById('listofids').value.split(",");
var error=false;
for(var i=0;i<allArray.length;i++) {
ProdRev = document.getElementById('Mfg_Spec_Prod_Approval_Rev'+allArray[i]);
ProdInit = document.getElementById('Mfg_Spec_Prod_Approval_Initials'+allArray[i]);
ProdRevValue = ProdRev[ProdRev.selectedIndex].value;
ProdInitValue = ProdInit[ProdInit.selectedIndex].value;
<!--- This code is if the BOM Initials is not empty and the PNR Initials is empty.--->
if(ProdInitValue != '' && ProdRevValue == '') {
error=true;
ecoNumber = document.getElementById('ECID'+allArray[i]).value;
partNumber = document.getElementById('Part_Number'+allArray[i]).value;
alert("You must enter a Rev for ECO " + ecoNumber + " Part Number: " + partNumber);
}
else if(ProdRevValue != '' && ProdInitValue == '') {
error=true;
ecoNumber = document.getElementById('ECID'+allArray[i]).value;
partNumber = document.getElementById('Part_Number'+allArray[i]).value;
alert("You must enter your initials for ECO " + ecoNumber + " Part Number: " + partNumber);
}
}
if(error) {
return false;
}
else {
return true;
}
}
</script>
Start of form
<cfform name="EditItem" method="post" action="My_Machining_action.cfm" onsubmit="return verify();">
<cfset MfgSpecProdInitials = DocumentationSearch.Mfg_Spec_Prod_Initials>
<td align="center">
<cfif Mfg_Spec_Prod_Initials Is Not ""<!--- and Mfg_Spec_Prod_Initials EQ cookie.UserInitials --->>
<select name="Mfg_Spec_Prod_Approval_Initials#ItemID#" id="Mfg_Spec_Prod_Approval_Initials#ItemID#">
<option value=""></option>
<cfloop query="ShowProdInitials">
<option value="#Initials#"
<cfif #Initials# EQ MfgSpecProdInitials>selected</cfif>>#Initials#</option>
</cfloop>
</select>
<cfelse>
</cfif>
</td>
<cfset MfgSpecProdRev = DocumentationSearch.Mfg_Spec_Prod_Rev>
<td align="center">
<cfif Mfg_Spec_Prod_Initials Is Not ""<!--- and Mfg_Spec_Prod_Initials EQ cookie.UserInitials --->>
<select name="Mfg_Spec_Prod_Approval_Rev#ItemID#" id="Mfg_Spec_Prod_Approval_Rev#ItemID#">
<option value=""></option>
<cfloop query="ShowDocRevChoices">
<option value="#Doc_Rev_Initials#"
<cfif #Doc_Rev_Initials# EQ MfgSpecProdRev>selected</cfif>>#Doc_Rev_Initials#</option>
</cfloop>
</select>
<cfelse>
</cfif>
</td>
<input type="submit" value="Update">