B
Bubba
I have a dynamic pulldown list (ASP with javascript) that when a user
picks a state, the corresponding counties for that state appear in a
dynamic second pulldown list. When I submit the form, the values for
state and county are numerals 1 (for the state) and 2 (for the county
selected) and not the values for the state and county
????
any help appreciated!
<!--#include file="dbaseconnection.asp" -->
<%
Dim rsMain
Dim rsMain_numRows
Set rsMain = Server.CreateObject("ADODB.Recordset")
rsMain.ActiveConnection = conn_STRING
rsMain.Source = "SELECT * FROM state_details ORDER BY state2 ASC"
rsMain.Open()
rsMain_numRows = 0
%>
<%
Dim rsSub
Dim rsSub_numRows
Set rsSub = Server.CreateObject("ADODB.Recordset")
rsSub.ActiveConnection = conn_STRING
rsSub.Source = "SELECT * FROM county_details ORDER BY county ASC"
rsSub.Open()
rsSub_numRows = 0
%>
<script language="JavaScript">
<!--
var arrDynaList = new Array();
var arrDL1 = new Array();
arrDL1[1] = "state"; // Name of parent list box
arrDL1[2] = "form1"; // Name of form containing parent list box
arrDL1[3] = "county"; // Name of child list box
arrDL1[4] = "form1"; // Name of form containing child list box
arrDL1[5] = arrDynaList; // No need to do anything here
<%
Dim txtDynaListRelation, txtDynaListLabel, txtDynaListValue,
oDynaListRS
txtDynaListRelation = "fkid" ' Name of recordset field relating to
parent
txtDynaListLabel = "county" ' Name of recordset field for child
Item Label
txtDynaListValue = "couid" ' Name of recordset field for child
Value
Set oDynaListRS = rsSub ' 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>
<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 = null;
}
oList.selectedIndex = -1;
}
/*This is a modified function from the original MM script. Mick White
added the first line of oList so there would be an initial selection.
Needed this if there is only 1 child menu item, otherwise, the single
child menu item would be already hihghlighted and you can not select
it. Also good for validation purposes so you can set the .js
validation to not allow the first selection.
*/
function populateDynaList(oList, nIndex, aArray){
oList[oList.length]= new Option("Please Select");
for (var i = 0; i < aArray.length; i= i + 3){
if (aArray == nIndex){
oList.options[oList.options.length] = new Option(aArray[i + 1],
aArray[i + 2]);
}
//oList.size=oList.length //You need to comment out this line of the
function if you use this mod
}
//A quick mod here, I changed the ==0 to ==1 so that the length
//takes into account the Please select option from above.
if (oList.options.length == 1){
oList.options[oList.options.length] = new Option(":: No
SubCategories Available ::");
}
oList.selectedIndex = 0;
}
//-->
</script>
<select name="state" id="state" size="10"
onChange="setDynaList(arrDL1)" class="select-type1">
<%
While (NOT rsMain.EOF)
%>
<option value="<%=(rsMain.Fields.Item("staid").Value)%>"><
%=(rsMain.Fields.Item("statefull").Value)%></option>
<%
rsMain.MoveNext()
Wend
If (rsMain.CursorType > 0) Then
rsMain.MoveFirst
Else
rsMain.Requery
End If
%>
</select>
<!-- here's the child/sub box 'county' , will display under not
side by side -->
<select name="county" id="county" size="10" class="select-type1">
</select>
<%
rsMain.Close()
Set rsMain = Nothing
%>
<%
rsSub.Close()
Set rsSub = Nothing
%>
picks a state, the corresponding counties for that state appear in a
dynamic second pulldown list. When I submit the form, the values for
state and county are numerals 1 (for the state) and 2 (for the county
selected) and not the values for the state and county
????
any help appreciated!
<!--#include file="dbaseconnection.asp" -->
<%
Dim rsMain
Dim rsMain_numRows
Set rsMain = Server.CreateObject("ADODB.Recordset")
rsMain.ActiveConnection = conn_STRING
rsMain.Source = "SELECT * FROM state_details ORDER BY state2 ASC"
rsMain.Open()
rsMain_numRows = 0
%>
<%
Dim rsSub
Dim rsSub_numRows
Set rsSub = Server.CreateObject("ADODB.Recordset")
rsSub.ActiveConnection = conn_STRING
rsSub.Source = "SELECT * FROM county_details ORDER BY county ASC"
rsSub.Open()
rsSub_numRows = 0
%>
<script language="JavaScript">
<!--
var arrDynaList = new Array();
var arrDL1 = new Array();
arrDL1[1] = "state"; // Name of parent list box
arrDL1[2] = "form1"; // Name of form containing parent list box
arrDL1[3] = "county"; // Name of child list box
arrDL1[4] = "form1"; // Name of form containing child list box
arrDL1[5] = arrDynaList; // No need to do anything here
<%
Dim txtDynaListRelation, txtDynaListLabel, txtDynaListValue,
oDynaListRS
txtDynaListRelation = "fkid" ' Name of recordset field relating to
parent
txtDynaListLabel = "county" ' Name of recordset field for child
Item Label
txtDynaListValue = "couid" ' Name of recordset field for child
Value
Set oDynaListRS = rsSub ' 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>
<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 = null;
}
oList.selectedIndex = -1;
}
/*This is a modified function from the original MM script. Mick White
added the first line of oList so there would be an initial selection.
Needed this if there is only 1 child menu item, otherwise, the single
child menu item would be already hihghlighted and you can not select
it. Also good for validation purposes so you can set the .js
validation to not allow the first selection.
*/
function populateDynaList(oList, nIndex, aArray){
oList[oList.length]= new Option("Please Select");
for (var i = 0; i < aArray.length; i= i + 3){
if (aArray == nIndex){
oList.options[oList.options.length] = new Option(aArray[i + 1],
aArray[i + 2]);
}
//oList.size=oList.length //You need to comment out this line of the
function if you use this mod
}
//A quick mod here, I changed the ==0 to ==1 so that the length
//takes into account the Please select option from above.
if (oList.options.length == 1){
oList.options[oList.options.length] = new Option(":: No
SubCategories Available ::");
}
oList.selectedIndex = 0;
}
//-->
</script>
<select name="state" id="state" size="10"
onChange="setDynaList(arrDL1)" class="select-type1">
<%
While (NOT rsMain.EOF)
%>
<option value="<%=(rsMain.Fields.Item("staid").Value)%>"><
%=(rsMain.Fields.Item("statefull").Value)%></option>
<%
rsMain.MoveNext()
Wend
If (rsMain.CursorType > 0) Then
rsMain.MoveFirst
Else
rsMain.Requery
End If
%>
</select>
<!-- here's the child/sub box 'county' , will display under not
side by side -->
<select name="county" id="county" size="10" class="select-type1">
</select>
<%
rsMain.Close()
Set rsMain = Nothing
%>
<%
rsSub.Close()
Set rsSub = Nothing
%>