select Drop-Down List item Based On Text Field not being empty
Hi. I have some javascript code to click on a button and it will insert the date into a text box called "Controller_PDF_Creation_Doc_Control_Date" on my form. I also have a drop down menu called "Release_Approval_Initials". All I'm trying to do is when there is a date entered into the text box, I want the "Release_Approval_Initials" drop down menu to default by selecting the option "TM". The drop down menu is dynamically populated too. How can I do this? Below is the code that I have.
<SCRIPT LANGUAGE="JavaScript">
function verify() {
var partNumber = '';
var ecoNumber = '';
var pdfDate;
var queue;
var queueValue='';
var allArray = document.getElementById('listofids').value.split(",");
var error=false;
for(var i=0;i<allArray.length;i++) {
pdfDate = document.getElementById('Controller_PDF_Creation_Doc_Control_Date'+allArray).value;
<!--- document.getElementById('Controller_PDF_Creation_Doc_Control_Date1').value='8/19/11'; --->
queue = document.getElementById('Release_Approval_Initials'+allArray);
queueValue = queue[queue.selectedIndex].value;
if((pdfDate != '' && queueValue == '') || (pdfDate == '' && queueValue != '')) {
error=true;
ecoNumber = document.getElementById('ECID'+allArray).value;
partNumber = document.getElementById('Part_Number'+allArray).value;
alert("You must enter both a PDF Creation and/or Doc Control approval date and Queue to Release for ECO " + ecoNumber + " Part Number: " + partNumber);
}
}
if(error) {
return false;
}
else {
return true;
}
}
</script>
<cfinput type="Text" name="Controller_PDF_Creation_Doc_Control_Date#ItemID#" id="Controller_PDF_Creation_Doc_Control_Date#ItemID#" value="#DateFormat(Controller_PDF_Creation_Doc_Control_Date,"M/D/YY")#" size="12" maxlength="8" validate="date" required="no" message="You must enter a valid date in M/D/YY format in the PDF Creation and/or Doc Control Date field">
<cfinput type="hidden" name="today_date" id="today_date" value="#DateFormat(now(),"M/D/YY")#" />
<input type= "button" value="Today's Date" onclick="document.getElementById('Controller_PDF_Creation_Doc_Control_Date#ItemID#').value=document.getElementById('today_date').value">
<select name="Release_Approval_Initials#ItemID#" id="Release_Approval_Initials#ItemID#">
<option value=""></option>
<cfloop query="ShowDataEntryInitials">
<option value="#Initials#"
<cfif Initials EQ ReleaseInitials>selected
</cfif>>#Initials#</option>
</cfloop>
</select>
Any help would be greatly appreciated. Thank you.
Andy
