Forums
This topic is locked
Dependent Dropdown tutorial.
Posted 30 Sep 2004 14:37:36
1
has voted
30 Sep 2004 14:37:36 shaun carter posted:
I have been trying the Macromedia dynamic dropdown tutorial at www.macromedia.com/support/dreamweaver/ts/documents/client_dynamic_listbox, but I get a blank page on my site, to view go to: www.motoringsw.com/sell and click cars, I have done everything the tutorial has ask, my db is sql (that's not an issue) I have added the java script in the heading where suggested, I have done this whole lab from scratch several times. I am using DW MX. Pleeeaase help me... Code included below, if you have anymore questions please mail me at , Thanks for reading this, best regards
Shaun
<pre id=code><font face=courier size=2 id=code> <%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<!--#include file="../Connections/mswdb.asp" -->
<%
var rslist1 = Server.CreateObject("ADODB.Recordset"

rslist1.ActiveConnection = MM_mswdb_STRING;
rslist1.Source = "SELECT Value FROM dbo.A_Parent ORDER BY Value ASC";
rslist1.CursorType = 0;
rslist1.CursorLocation = 2;
rslist1.LockType = 1;
rslist1.Open();
var rslist1_numRows = 0;
%>
<%
var rslist2 = Server.CreateObject("ADODB.Recordset"

rslist2.ActiveConnection = MM_mswdb_STRING;
rslist2.Source = "SELECT Label FROM dbo.A_Child ORDER BY Label ASC";
rslist2.CursorType = 0;
rslist2.CursorLocation = 2;
rslist2.LockType = 1;
rslist2.Open();
var rslist2_numRows = 0;
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- Dynamic Dependent List box Code for *** JavaScript *** Server Model //-->
<script language="JavaScript">
<!--
var arrDynaList = new Array();
var arrDL1 = new Array();
arrDL1[1] = "selList1"; // Name of parent list box
arrDL1[2] = "form1"; // Name of form containing parent list box
arrDL1[3] = "selList2"; // Name of child list box
arrDL1[4] = "form1"; // Name of form containing child list box
arrDL1[5] = arrDynaList;
<%
var txtDynaListRelation, txtDynaListLabel, txtDynaListValue, oDynaListRS;
txtDynaListRelation = "Relation" // Name of recordset field relating to parent
txtDynaListLabel = "Label" // Name of recordset field for child Item Label
txtDynaListValue = "[Value]" // Name of recordset field for child Value
oDynaListRS = rsList2 // Name of child list box recordset
var varDynaList = -1;
var varMaxWidth = "1";
var varCheckGroup = oDynaListRS.Fields.Item(txtDynaListRelation).Value;
var varCheckLength = 0;
var varMaxLength = 0;
while (!oDynaListRS.EOF){
if (varCheckGroup != oDynaListRS.Fields.Item(txtDynaListRelation).Value) {
varMaxLength = Math.max(varCheckLength, varMaxLength)
varCheckLength = 0;
}
%>
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 (oDynaListRS.Fields.Item(txtDynaListLabel).Value.length > varMaxWidth.length) {
varMaxWidth = oDynaListRS.Fields.Item(txtDynaListLabel).Value;
}
varCheckLength = varCheckLength + 1;
varDynaList = varDynaList + 3;
oDynaListRS.MoveNext();
}
varMaxLength = Math.max(varCheckLength, varMaxLength)
%>
//-->
</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>
</head>
<body>
<form name="form1" method="post" action="">
<table width="90%" border="2" cellpadding="2">
<tr>
<td> </td>
<td><select name="sellist1" id="sellist1" onChange="MM_callJS('setDynaList(arrDL1)')">
<%
while (!rslist1.EOF) {
%>
<option value="<%=(rslist1.Fields.Item("Value"


<%
rslist1.MoveNext();
}
if (rslist1.CursorType > 0) {
if (!rslist1.BOF) rslist1.MoveFirst();
} else {
rslist1.Requery();
}
%>
</select></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><select name="sellist2" id="sellist2">
</select></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</form>
</body>
</html>
<%
rslist1.Close();
%>
<%
rslist2.Close();
%>
</font id=code></pre id=code>
Replies
Replied 04 Oct 2004 20:52:44
04 Oct 2004 20:52:44 Rene Bandsma replied:
Why not buy WA Dynamic Dropdowns from webassist.com?