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> &lt;%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%&gt;
&lt;!--#include file="../Connections/mswdb.asp" --&gt;
&lt;%
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;
%&gt;
&lt;%
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;
%&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;!-- Dynamic Dependent List box Code for *** JavaScript *** Server Model //--&gt;
&lt;script language="JavaScript"&gt;
&lt;!--

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;

&lt;%
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;
}
%&gt;
arrDynaList[&lt;%=(varDynaList+1)%&gt;] = "&lt;%=(oDynaListRS.Fields.Item(txtDynaListRelation).Value)%&gt;";
arrDynaList[&lt;%=(varDynaList+2)%&gt;] = "&lt;%=(oDynaListRS.Fields.Item(txtDynaListLabel).Value)%&gt;";
arrDynaList[&lt;%=(varDynaList+3)%&gt;] = "&lt;%=(oDynaListRS.Fields.Item(txtDynaListValue).Value)%&gt;";
&lt;%

if (oDynaListRS.Fields.Item(txtDynaListLabel).Value.length &gt; varMaxWidth.length) {
varMaxWidth = oDynaListRS.Fields.Item(txtDynaListLabel).Value;
}
varCheckLength = varCheckLength + 1;
varDynaList = varDynaList + 3;
oDynaListRS.MoveNext();
}
varMaxLength = Math.max(varCheckLength, varMaxLength)
%&gt;


//--&gt;
&lt;/script&gt;

&lt;!-- End of object/array definitions, beginning of generic functions --&gt;

&lt;script language="JavaScript"&gt;
&lt;!--
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 &gt;= 0; i--){
oList.options[i] = null;
}

oList.selectedIndex = -1;
}

function populateDynaList(oList, nIndex, aArray){

for (var i = 0; i &lt; 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)
}
//--&gt;
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;form name="form1" method="post" action=""&gt;
&lt;table width="90%" border="2" cellpadding="2"&gt;
&lt;tr&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&lt;select name="sellist1" id="sellist1" onChange="MM_callJS('setDynaList(arrDL1)')"&gt;
&lt;%
while (!rslist1.EOF) {
%&gt;
&lt;option value="&lt;%=(rslist1.Fields.Item("Value".Value)%&gt;"&gt;&lt;%=(rslist1.Fields.Item("Value".Value)%&gt;&lt;/option&gt;
&lt;%
rslist1.MoveNext();
}
if (rslist1.CursorType &gt; 0) {
if (!rslist1.BOF) rslist1.MoveFirst();
} else {
rslist1.Requery();
}
%&gt;
&lt;/select&gt;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&lt;select name="sellist2" id="sellist2"&gt;
&lt;/select&gt;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;%
rslist1.Close();
%&gt;
&lt;%
rslist2.Close();
%&gt;
</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?

Reply to this topic