virtualranger
Technical User
Looked thru the FAQ's and found some useful tips on Dynamic list boxes. Unfortunately my code isn't working. Must be something simple. I know the recordset contents are correct. There is no error when I load the page, the first list box populates correctly but it won't populate the second. Possibly a problem with calling the changeOptions function?
Can anyone point out where I've gone wrong?
Thanks,
Jamie
Can anyone point out where I've gone wrong?
Code:
<% @ LANGUAGE = VBScript%>
<%
Option Explicit
Stuff here to create connections...
Dim str_sql
str_sql = "SELECT devCountry, devCounty " & _
"FROM Results " & _
"ORDER BY devCountry, devCounty"
Set rsCountry = objConn.Execute(str_sql)
%>
<html>
<head>
<script language="javascript">
var dataArray = new Array(<%
If Not rsCountry.EOF Then rsCountry.MoveFirst
Dim last_item
Do Until rsCountry.EOF
'check if the first column item is equal to its value
' from the previous loop, if not start a new array
If last_item <> rsCountry("devCountry") Then
'if there was a last item, finish the previous array
If len(last_item) > 0 Then Response.Write ")"
'start a new array
Response.Write ",new Array("
'record last item
last_item = rsCountry("devCountry")
End If
'output the second column value preceded by a comma
Response.Write "," & rsCountry("devCounty")
'queue to next record
rsCountry.MoveNext
Loop
'finish open array if there was a last item
If len(last_item) > 0 Then Response.Write ")"
%>);
function changeOptions(elemOne,elemTwo){
var i;
//clear out previous options leaving the top generic text
for(i = elemTwo.options.length; i >= 1; i--)
elemTwo.options[i] = null;
elemTwo.selectedIndex = 0;
//if the selected index in the first one is 0 escape out
if(elemOne.selectedIndex == 0)
return false;
//populate second one
for(i=1;i<dataArray.length;i++){
elemTwo.options[i] = new Option(dataArray[elemOne.selectedIndex][i],elemOne.selectedIndex][i]);
}
}
</script>
</head>
<body>
<form method="POST" action="whatever.asp">
<select name="selType"
onchange="changeOptions(this,document.getElementsByName('selCounty'))">
<option value>[ Select Country ]</option>
<%
'the only way the RS could be BOF at this point is if it was empty
If Not rsCountry.BOF Then rsCountry.MoveFirst
Dim last_Country
Do Until rsCountry.EOF
If rsCountry("devCountry") <> last_Country Then
Response.Write "<option>" & rsCountry("devCountry") & "</option>"
last_Country = rsCountry("devCountry")
End If
rsCountry.MoveNext
Loop
%>
</select> <select name="selCounty">
<option value>[ Select County ]</option>
</select> <input type="submit" value="Search">
</form>
<%
rsCountry.Close
objConn.Close
Set rsCountry=Nothing
Set objConn=Nothing
%>
</body>
</html>
Thanks,
Jamie