|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
I want to link 2 list boxes on the same page without reloading it. The list boxes are dynamic and when one selects an item in the first one, the second one get's populated accordingly. So far I've been stuck with Javascript Object Expected Error and I cant find a way to make it work. Please, Help
here is the code... <%@LANGUAGE="VBSCRIPT"%> <!--#include file="connection.asp"--> <% Dim SQL1, Recordset1 SQL1 = "SELECT distinct DESCRIPTION FROM materials" Set Recordset1 = Conn.Execute(SQL1) %> <% Dim SQL2, Recordset2 SQL2 = "SELECT distinct DESCRIPTION, SPECIFICS FROM materials" Set Recordset2 = Conn.Execute(SQL2) %> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <form name="Form1" method="POST" action=""> <SELECT SIZE=8 NAME=descriptionList STYLE="width: 120pt" onchange="setDynaList()"> <%While Not Recordset1.EOF%> <option value="<%=Recordset1("description")%>"> <%=Recordset1.Fields("description")%> </option> <% Recordset1.MoveNext Wend %> </SELECT> <SELECT SIZE=8 NAME=specificsList> </select> </form> </body> </html> <SCRIPT LANGUAGE="Javascript"> var arrDynaList = new Array(); <% count1 = 0 count2 = 0 While (NOT Recordset2.EOF) If Recordset2.fields.name = "description" Then %> arrDynaList[<%=count1%>,<%=count2%> ] = "<%=(Recordset2.Fields.Item("description").Value)%>"; arrDynaList[<%=count1%>,<%=count2+1%> ] = "<%=(Recordset2.Fields.Item("specifics").Value)%>"; <% count2 = 0 count1=count1+1 End If Recordset2.MoveNext() Wend %> function setDynaList(){ var oList1 = document.Form1.descriptionList; var oList2 = document.Form1.specificsList; clearDynaList(oList2); if (oList1.selectedIndex == -1){ oList1.selectedIndex = 0; } populateDynaList(oList2, oList1[oList1.selectedIndex].value, arrDynaList); return true; } function clearDynaList(oList){ //clears out a list 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 + 1){ for (var j = 0; j < 2; j=j+1){ if (aArray[i,j] == nIndex){ oList.options[oList.options.length] = new Option(aArray[i], aArray[j]); } } } if (oList.options.length == 0){ oList.options[oList.options.length] = new Option(["none available"],0); } oList.selectedIndex = (0); } </SCRIPT> <% Recordset1.Close %> <% Recordset2.Close Conn.Close %> |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > dynamically linked list boxes |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|