Forums
This topic is locked
Dynamic dropdown menus problem
31 Jan 2005 18:48:40 Wim Conix posted:
Hello,I'm making a search page with two dynamic dropdown menus, the second filled filtered by the first.
I found a tutorial from Macromedia on how to do this.
I get no error reports, but... nothing happens to the second when I change the first.
Can someone plese take a look at the code I copied and changed for my purposes.
Does anyone know what the problem can be ??
Must be something with the recordsets or the code from Macromedia... or the link between the two menus...
Recordsets for the menus :
<%
Dim rs_author
Dim rs_author_numRows
Set rs_author = Server.CreateObject("ADODB.Recordset"

rs_author.ActiveConnection = MM_conn_photodat_sql_STRING
rs_author.Source = "SELECT DISTINCT ID, Author FROM Users ORDER BY Author"
rs_author.CursorType = 0
rs_author.CursorLocation = 2
rs_author.LockType = 1
rs_author.Open()
rs_author_numRows = 0
%>
<%
Dim rs_Gallery
Dim rs_Gallery_numRows
Set rs_Gallery = Server.CreateObject("ADODB.Recordset"

rs_Gallery.ActiveConnection = MM_conn_photodat_sql_STRING
rs_Gallery.Source = "SELECT DISTINCT ID, Gallery, Author FROM Galleries ORDER BY Gallery"
rs_Gallery.CursorType = 0
rs_Gallery.CursorLocation = 2
rs_Gallery.LockType = 1
rs_Gallery.Open()
rs_Gallery_numRows = 0
%>
Code from Macromedia :
<!-- Dynamic Dependent List box Code for *** VBScript *** 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] = "
form2
"; // Name of form containing child list box
arrDL1[5] = arrDynaList;
<%
Dim 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
Set oDynaListRS =
rsList2
' Name of child list box recordset
Dim varDynaList
varDynaList = -1
Dim varMaxWidth
varMaxWidth = "1"
Dim varCheckGroup
varCheckGroup = oDynaListRS.Fields.Item(txtDynaListRelation).Value
Dim varCheckLength
varCheckLength = 0
Dim varMaxLength
varMaxLength = 0
While (NOT oDynaListRS.EOF)
If (varCheckGroup <> oDynaListRS.Fields.Item(txtDynaListRelation).Value) Then
If (varCheckLength > varMaxLength) Then
varMaxLength = varCheckLength
End If
varCheckLength = 0
End If
%>
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 (len(oDynaListRS.Fields.Item(txtDynaListLabel).Value) > len(varMaxWidth)) Then
varMaxWidth = oDynaListRS.Fields.Item(txtDynaListLabel).Value
End If
varCheckLength = varCheckLength + 1
varDynaList = varDynaList + 3
oDynaListRS.MoveNext()
Wend
If (varCheckLength > varMaxLength) Then
varMaxLength = varCheckLength
End If
%>
//-->
</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;
}
//-->
</script>
Thanks for any help,
Wim
Replies
Replied 01 Feb 2005 10:18:38
01 Feb 2005 10:18:38 Vince Baker replied:
I notice that in the code where you specify the name of the value and label to be displayed in the dropdown you have not specified which recordset fields you want displayed.
Change this and you should be good to go.
Regards
Vince
DMX Talkzone Manager
Visit my home: www.chez-vince.com
(Now completely CSS based and bye bye to all tables!)
VBScript | ASP | HTML | CSS | SQL | Oracle | Hosting
Change this and you should be good to go.
Regards
Vince
DMX Talkzone Manager
Visit my home: www.chez-vince.com
(Now completely CSS based and bye bye to all tables!)
VBScript | ASP | HTML | CSS | SQL | Oracle | Hosting
Replied 01 Feb 2005 16:03:57
01 Feb 2005 16:03:57 Wim Conix replied:
Thanks Vince,
I filled in the necessary fields, but still no go...
I must be linking the two dropdowns somewhere wrong...
I didn't change the recordsets, only the linking part.
You can see what I'm trying to make at www.image-belle.com/asp/images/search_quick_02.asp
Can't be that difficult, I guess...
Recordsets :
<%
Dim rs_author
Dim rs_author_numRows
Set rs_author = Server.CreateObject("ADODB.Recordset"
rs_author.ActiveConnection = MM_conn_photodat_sql_STRING
rs_author.Source = "SELECT DISTINCT ID, Author FROM Users ORDER BY Author"
rs_author.CursorType = 0
rs_author.CursorLocation = 2
rs_author.LockType = 1
rs_author.Open()
rs_author_numRows = 0
%>
<%
Dim rs_Gallery
Dim rs_Gallery_numRows
Set rs_Gallery = Server.CreateObject("ADODB.Recordset"
rs_Gallery.ActiveConnection = MM_conn_photodat_sql_STRING
rs_Gallery.Source = "SELECT DISTINCT ID, Gallery, Author FROM Galleries ORDER BY Gallery"
rs_Gallery.CursorType = 0
rs_Gallery.CursorLocation = 2
rs_Gallery.LockType = 1
rs_Gallery.Open()
rs_Gallery_numRows = 0
%>
Linking code :
<!-- Dynamic Dependent List box Code for *** VBScript *** Server Model //-->
<script language="JavaScript">
<!--
var arrDynaList = new Array();
var arrDL1 = new Array();
arrDL1[1] = "select_author";
// Name of parent list box
arrDL1[2] = "form1";
// Name of form containing parent list box
arrDL1[3] = "select_gallery";
// Name of child list box
arrDL1[4] = "form1";
// Name of form containing child list box
arrDL1[5] = arrDynaList;
<%
Dim txtDynaListRelation, txtDynaListLabel, txtDynaListValue, oDynaListRS
txtDynaListRelation = "Author"
' Name of recordset field relating to parent
txtDynaListLabel = "Gallery"
' Name of recordset field for child Item Label
txtDynaListValue = "ID"
' Name of recordset field for child Value
Set oDynaListRS = rs_Gallery
' Name of child list box recordset
Thanks for help,
Wim
I filled in the necessary fields, but still no go...
I must be linking the two dropdowns somewhere wrong...
I didn't change the recordsets, only the linking part.
You can see what I'm trying to make at www.image-belle.com/asp/images/search_quick_02.asp
Can't be that difficult, I guess...
Recordsets :
<%
Dim rs_author
Dim rs_author_numRows
Set rs_author = Server.CreateObject("ADODB.Recordset"

rs_author.ActiveConnection = MM_conn_photodat_sql_STRING
rs_author.Source = "SELECT DISTINCT ID, Author FROM Users ORDER BY Author"
rs_author.CursorType = 0
rs_author.CursorLocation = 2
rs_author.LockType = 1
rs_author.Open()
rs_author_numRows = 0
%>
<%
Dim rs_Gallery
Dim rs_Gallery_numRows
Set rs_Gallery = Server.CreateObject("ADODB.Recordset"

rs_Gallery.ActiveConnection = MM_conn_photodat_sql_STRING
rs_Gallery.Source = "SELECT DISTINCT ID, Gallery, Author FROM Galleries ORDER BY Gallery"
rs_Gallery.CursorType = 0
rs_Gallery.CursorLocation = 2
rs_Gallery.LockType = 1
rs_Gallery.Open()
rs_Gallery_numRows = 0
%>
Linking code :
<!-- Dynamic Dependent List box Code for *** VBScript *** Server Model //-->
<script language="JavaScript">
<!--
var arrDynaList = new Array();
var arrDL1 = new Array();
arrDL1[1] = "select_author";
// Name of parent list box
arrDL1[2] = "form1";
// Name of form containing parent list box
arrDL1[3] = "select_gallery";
// Name of child list box
arrDL1[4] = "form1";
// Name of form containing child list box
arrDL1[5] = arrDynaList;
<%
Dim txtDynaListRelation, txtDynaListLabel, txtDynaListValue, oDynaListRS
txtDynaListRelation = "Author"
' Name of recordset field relating to parent
txtDynaListLabel = "Gallery"
' Name of recordset field for child Item Label
txtDynaListValue = "ID"
' Name of recordset field for child Value
Set oDynaListRS = rs_Gallery
' Name of child list box recordset
Thanks for help,
Wim
Replied 01 Feb 2005 16:09:48
01 Feb 2005 16:09:48 Vince Baker replied:
Not sure why it is not working....all looks ok, I tried to view your page but never finished loading.
What exactly is the error (or is the error the page doesnt load)
Regards
Vince
DMX Talkzone Manager
Visit my home: www.chez-vince.com
(Now completely CSS based and bye bye to all tables!)
VBScript | ASP | HTML | CSS | SQL | Oracle | Hosting
What exactly is the error (or is the error the page doesnt load)
Regards
Vince
DMX Talkzone Manager
Visit my home: www.chez-vince.com
(Now completely CSS based and bye bye to all tables!)
VBScript | ASP | HTML | CSS | SQL | Oracle | Hosting
Replied 01 Feb 2005 16:11:40
01 Feb 2005 16:11:40 Wim Conix replied:
Vince,
Problem solved !!
Tried some other link fields and that must have been the problem.
Thanks for your help !!
Wim
Problem solved !!
Tried some other link fields and that must have been the problem.
Thanks for your help !!
Wim
Replied 01 Feb 2005 16:16:28
01 Feb 2005 16:16:28 Wim Conix replied: