ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old July 31st, 2003, 12:20 PM
pivko4life pivko4life is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 1 pivko4life User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question dynamically linked list boxes

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
%>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > dynamically linked list boxes


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway