Greetings,
I have an ASP page with two dynamic dependent list boxes written in JavaScript. My dependent lists work great, but my problem is that the values for "Program_Na me" and "Project_Na me" are passed onto this page from a previous page and I haven't been able to figure out how to show the passed values in the list boxes when the page loads.
All variables passed perfectly before I added the dependent list code below. Currently, when the page loads, there are no values for "Program_Na me" or "Project_Na me". However, when I make a change to "EZWorkstre am", the onChange events fire perfectly and values then appear in my dependent list boxes.
I'm far from an expert in JavaScript (the code below I adapted from Adobe.com), so here's what I have (I hope it isn't too much):
Here also FYI are the Call JavaScript behaviors for my onChange and body onLoad events:
Whatever help someone can provide would be greatly appreciated.
JM
I have an ASP page with two dynamic dependent list boxes written in JavaScript. My dependent lists work great, but my problem is that the values for "Program_Na me" and "Project_Na me" are passed onto this page from a previous page and I haven't been able to figure out how to show the passed values in the list boxes when the page loads.
All variables passed perfectly before I added the dependent list code below. Currently, when the page loads, there are no values for "Program_Na me" or "Project_Na me". However, when I make a change to "EZWorkstre am", the onChange events fire perfectly and values then appear in my dependent list boxes.
I'm far from an expert in JavaScript (the code below I adapted from Adobe.com), so here's what I have (I hope it isn't too much):
Code:
<!-- Dynamic Dependent List box Code for *** VBScript *** Server Model //--><script language="JavaScript"><!--
var arrDynaList2 = new Array();
var arrDL2 = new Array();
arrDL2[1] = "EZworkstream"; // Name of parent list box
arrDL2[2] = "form1"; // Name of form containing parent list box
arrDL2[3] = "Program_Name"; // Name of child list box
arrDL2[4] = "form1"; // Name of form containing child list box
arrDL2[5] = arrDynaList2;
<%
Dim txtDynaListRelation2, txtDynaListLabel2, txtDynaListValue2, oDynaListRS2
txtDynaListRelation2 = "CategoryID" ' Name of recordset field relating to parent
txtDynaListLabel2 = "Program_Name" ' Name of recordset field for child Item Label
txtDynaListValue2 = "SubCat_ID" ' Name of recordset field for child Value
Set oDynaListRS2 = Program_Name ' Name of child list box recordset
Dim varDynaList2
varDynaList2 = -1
Dim varMaxWidth2
varMaxWidth2 = "1"
Dim varCheckGroup2
varCheckGroup2 = oDynaListRS2.Fields.Item(txtDynaListRelation2).Value
Dim varCheckLength2
varCheckLength2 = 0
Dim varMaxLength2
varMaxLength2 = 0
While (NOT oDynaListRS2.EOF)
If (varCheckGroup2 <> oDynaListRS2.Fields.Item(txtDynaListRelation2).Value) Then
If (varCheckLength2 > varMaxLength2) Then
varMaxLength2 = varCheckLength2
End If
varCheckLength2 = 0
End If
%>
arrDynaList2[<%=(varDynaList2+1)%>] = "<%=(oDynaListRS2.Fields.Item(txtDynaListRelation2).Value)%>"
arrDynaList2[<%=(varDynaList2+2)%>] = "<%=(oDynaListRS2.Fields.Item(txtDynaListLabel2).Value)%>"
arrDynaList2[<%=(varDynaList2+3)%>] = "<%=(oDynaListRS2.Fields.Item(txtDynaListValue2).Value)%>"<%
If (len(oDynaListRS2.Fields.Item(txtDynaListLabel2).Value) > len(varMaxWidth2)) Then
varMaxWidth2 = oDynaListRS2.Fields.Item(txtDynaListLabel2).Value
End If
varCheckLength2 = varCheckLength2 + 1
varDynaList2 = varDynaList2 + 3
oDynaListRS2.MoveNext()
Wend
If (varCheckLength2 > varMaxLength2) Then
varMaxLength2 = varCheckLength2
End If
%>
var arrDynaList = new Array();
var arrDL1 = new Array();
arrDL1[1] = "Program_Name"; // Name of parent list box
arrDL1[2] = "form1"; // Name of form containing parent list box
arrDL1[3] = "Project_Name"; // Name of child list box
arrDL1[4] = "form1"; // Name of form containing child list box
arrDL1[5] = arrDynaList;<%
Dim txtDynaListRelation, txtDynaListLabel, txtDynaListValue, oDynaListRS
txtDynaListRelation = "CategoryID" ' Name of recordset field relating to parent
txtDynaListLabel = "Project_Name" ' Name of recordset field for child Item Label
txtDynaListValue = "SubCat_ID" ' Name of recordset field for child Value
Set oDynaListRS = ProjectName ' Name of child list box recordset
Dim varDynaList
varDynaList = -1
Dim varMaxWidth
varMaxWidth = "1"
Dim varCheckGroup
varCheckGroup = oDynaListRS.Fields.Item(txtDynaListRelation).Value
Dim varCheckLength
varCheckLength = 0
Dim varMaxLength
varMaxLength = 0
While (NOT oDynaListRS.EOF)
If (varCheckGroup <> oDynaListRS.Fields.Item(txtDynaListRelation).Value) Then
If (varCheckLength > varMaxLength) Then
varMaxLength = varCheckLength
End If
varCheckLength = 0
End If
%>
arrDynaList[<%=(varDynaList+1)%>] = "<%=(oDynaListRS.Fields.Item(txtDynaListRelation).Value)%>"
arrDynaList[<%=(varDynaList+2)%>] = "<%=(oDynaListRS.Fields.Item(txtDynaListLabel).Value)%>"
arrDynaList[<%=(varDynaList+3)%>] = "<%=(oDynaListRS.Fields.Item(txtDynaListValue).Value)%>"<%
If (len(oDynaListRS.Fields.Item(txtDynaListLabel).Value) > len(varMaxWidth)) Then
varMaxWidth = oDynaListRS.Fields.Item(txtDynaListLabel).Value
End If
varCheckLength = varCheckLength + 1
varDynaList = varDynaList + 3
oDynaListRS.MoveNext()
Wend
If (varCheckLength > varMaxLength) Then
varMaxLength = varCheckLength
End If
%>
//--></script><!-- End of object/array definitions, beginning of generic functions --><script language="JavaScript">
<!--
function setDynaList(arrDL){
var oList1 = document.forms[arrDL[2]].elements[arrDL[1]];
var oList2 = document.forms[arrDL[4]].elements[arrDL[3]];
var arrList = arrDL[5];
clearDynaList(oList2);
if (oList1.selectedIndex == -1){
oList1.selectedIndex = 0;
}
populateDynaList(oList2, oList1[oList1.selectedIndex].value, arrList);
return true;
}
function clearDynaList(oList){
for (var i = oList.options.length; i >= 0; i--){
oList.options[i] = null;
}
oList.selectedIndex = -1;
}
function populateDynaList(oList, nIndex, aArray){
for (var i = 0; i < aArray.length; i= i + 3){
if (aArray[i] == nIndex){
oList.options[oList.options.length] = new Option(aArray[i + 1], aArray[i + 2]);
}
}
if (oList.options.length == 0){
oList.options[oList.options.length] = new Option("[none available]",0);
}
oList.selectedIndex = 0;
}
function MM_callJS(jsStr) { //v2.0
return eval(jsStr)
}
//-->
</script>
Code:
<select name="EZworkstream" class="style3" id="EZworkstream" onchange="MM_callJS('setDynaList(arrDL2)');MM_callJS('setDynaList(arrDL1)')">
<select name="Program_Name" class="style3" id="Program_Name" onchange="MM_callJS('setDynaList(arrDL1)')">
JM
Comment