ASP
--
Questions
--
Followers
Top Experts
I use a javascript function to correspond with my Access-database, which is called in the different select tags by an 'onchange' eventhandler.
The problem is that it only works when you select the
first item out of the first drop down menu. In other words: the key of the first drop down menu is always 1.
Does anyone has an example of a 3-way drop down menu which
is filled dynamical using the 'onchange' eventhandler?
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
so if you want it... i'd be glad to copy and paste it to you...
MaxOvrdrv2
Try to check out this link... might help...
https://www.experts-exchange.com/questions/20458348/dynamic-dropdown-listboxs-extracted-from-database.html
HAppy programming...






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
To make it three dropdown you need to make another list box with the value as location.href... Now with a little modification..that is to carry the request.querystring of the firstdropdown and the second dropdown so that on the next loading tyhe first will not change.
This what I mean... Kindly check out the script and do the necessary adjustment regarding the databasename, tablename, fieldname and the related query depending on your existing db.
=====saver this as dropdown.asp
<%Dim oConn, dbPath
dbPath = Server.MapPath("db3.mdb")
Set oConn=Server.CreateObject(
oConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & dbPath & ";"
set rs = Server.CreateObject("ADODB
sql = "SELECT * FROM Table1"
rs.Open sql, oConn
%>
<html>
<head>
<title>Virtual Hosting | Members Area</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1253">
</head>
<script language="Javascript">
function doSel(obj)
{
for (i = 0; i < obj.length; i++)
if (obj[i].selected == true)
eval(obj[i].value);
}
</script>
<body>
<select name="Ref_ID" onchange="doSel(this)">
<option value="">Please select</option>
<%Do while not(rs.eof)%>
<option value="location.href='drop
<%
rs.movenext
loop
%>
</select>
<%if request.querystring("id2")
set rs2 = Server.CreateObject("ADODB
sql = "SELECT * FROM Table1 WHERE ID = '"& request.querystring("id") &"'"
rs2.Open sql, oConn%>
<select name="Ref_ID2" onchange="doSel(this)">
<option value="">Please select</option>
<%Do while not(rs2.eof)%>
<option value="location.href='drop
<%
rs2.movenext
loop%>
</select>
<%rs2.Close()
Set rs2 = Nothing
<%else%>
<SELECT size="1" name="Ref_ID2">
<OPTION VALUE="">Select Option 2</OPTION>
</SELECT>
<%end if%>
<%if request.querystring("id2")
set rs3 = Server.CreateObject("ADODB
sql = "SELECT * FROM Table1 WHERE ID = '"& request.querystring("id2")
rs3.Open sql, oConn%>
<select name="Ref_ID3" onchange="doSel(this)">
<option value="">Please select</option>
<%Do while not(rs3.eof)%>
<option value="<%=rs3("ID")%>"><%=
<%
rs3.movenext
loop%>
</select>
<%rs3.Close()
Set rs3 = Nothing
<%else%>
<SELECT size="1" name="Ref_ID3">
<OPTION VALUE=""> Select Option 3 </OPTION>
</SELECT>
<%end if%>
</body>
</html>
<%
rs.Close()
Set rs = Nothing
%>
HTH...
Happy programming...
Something I forgot the say:
every drop down menu gets its data from a different table.
So there are 3 tables which are connected with each other
using keys.
So when you make a selection in the first drop down menu,
the corresonding key is used to go to the second table
to fill the second drop down menu. When a selection is made in the second drop down menu, the first key (of the selected item out of the first drop down menu)and the second key (of the selected item out of the second drop down menu) are used to get the right data out of the third
table.
How do I adapt your coding to make it work?
Thanks in advance !!!

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
BAsically when the page reload it will create a new recordset for that certain dropdown as you can see
the first is called rs which get it data on the TABLE1
set rs = Server.CreateObject("ADODB
sql = "SELECT * FROM Table1"
rs.Open sql, oConn
the second is called rs2 which get it data on the same table which is TABLE1
<%if request.querystring("id2")
set rs2 = Server.CreateObject("ADODB
sql = "SELECT * FROM Table1 WHERE ID = '"& request.querystring("id") &"'"
rs2.Open sql, oConn%>
the third is called rs3 which also get it data on the same table which is TABLE1
<%if request.querystring("id2")
set rs3 = Server.CreateObject("ADODB
sql = "SELECT * FROM Table1 WHERE ID = '"& request.querystring("id2")
rs3.Open sql, oConn%>
Just change the TABLE1 base on your existing TABLE where the second dropdown will get its data... same with the third dropdown3...
HTH...
HAppy programming....
It still doesn't work, the fact is that the second and the
third drop down menus aren't filled.
The program only runs through
<%else%>
<SELECT size="1" name="Ref_ID2">
<OPTION VALUE="">Select Option 2</OPTION>
</SELECT>
and
<%else%>
<SELECT size="1" name="Ref_ID3">
<OPTION VALUE=""> Select Option 3 </OPTION>
</SELECT>
So in the second drop down menu, only 'Select option 2' is
visible and no data from the table is displayed. The same
for the third drop down menu.
Sorry for my small ASP-knowledge ...
---CODE----
<!-- #INCLUDE FILE="Functions.inc" -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.
<link rel="stylesheet" type="text/css" href="fontcss.css">
<title>BMC Monthly Report</title>
</head>
<body>
<!-- #INCLUDE FILE="LeftMenu.inc" -->
<%
BMCRepType=TRIM(Request("B
%>
<center><font size="5" face="Georgia" color="#006600"><b>BMC Reports</b></font></center
<br><br>
<center><font size="5" face="Georgia" color="#006600"><b>BMC Monthly Report</b></font></center>
<center><form type="post" name="reptype" action="BMCMonthly.asp?BMC
<table width="50%" height="10%" cellspacing="1" cellpadding="0" border="1" >
<tr width="100%" height="50%" bgcolor="#0000FF">
<td><center><font size="3" face="Georgia" color="#FFFFFF"><b>Choose Report Type!</b></font></center><
</tr>
<tr width="100%" height="50%" bgcolor="#0000FF">
<td><center><select name="BMCRepType" size="1" onchange="SubmitForm(repty
<option value="None">--Select Type--</option>
<option value="Monthly" <%if BMCRepType="Monthly" then%>SELECTED<%end if%>>by Month</option>
<option value="Category" <%if BMCRepType="Category" then%>SELECTED<%end if%>>by Category</option>
</select></center>
</td>
</tr>
</form></center>
<%
%>
<br><br>
<%
'create an instance of the connection object
Set Con = Server.CreateObject("ADODB
Con.Open "filedsn=NewProjectTrackin
Set RS = Server.CreateObject("ADODB
RS.ActiveConnection = Con 'set recordset connection
RS.CursorType=1 'set recordset to be able to modify information
RS.CursorLocation=2
RS.LockType=3
if BMCRepType="None" then
%>
<center><font size="5" face="Georgia" color="#006600"><b>SXD Project Tracking:<br><b>BMC Reports</b></b></font></ce
<br><br>
<center><font size="3" face="Georgia" color="#006600"><b>You Did Not Select A Report Type!! <a href="BMCRep.asp" target="main">Click Here </a>to go back!</b></font></center>
<%
response.end
end if
if BMCRepType="Monthly" then
RS.Open "SELECT * FROM [Review Cycles] ORDER BY [Cycle Month] DESC"
else
RS.Open "SELECT * FROM Categories ORDER BY Cat_ID"
end if
if RS.EOF then
%>
<center><table width="60%" border="2" cellpadding="0" cellspacing="0" bgcolor="#D2D2D2">
<tr>
<td><b>Error:</b> There is a problem with the Database... Please contact the <b>Project Tracking Administrator, Jennifer Carey or Joe Valenzuela IMMEDIATELY!</b> Reports will not be generated! Thank You For Your Cooperation!
</td>
</tr>
</table></center>
<%
end if
%>
<center><form type="post" name="month" action="" width="60%">
<table width="50%" height="10%" cellspacing="1" cellpadding="0" border="1">
<tr width="100%" height="50%" bgcolor="#0000FF">
<td><center><font face="Georgia" size="3" color="#FFFFFF"><b><%if BMCRepType="Monthly" then%>Choose Report Month!<%else%>Choose Report Category!<%end if%></b></font></center></
</tr>
<tr width="100%" height="50%" bgcolor="#0000FF">
<td><center><select name="cmonth" size="1" onChange="window.open('Pro
<option value="None"><%if BMCRepType="Monthly" then%>--Select a Month--<%else%>--Select a Category--<%end if%></option>
<%
RS.MoveFirst
Dim MonthArray(11)
MonthArray(0)="January"
MonthArray(1)="Feburary"
MonthArray(2)="March"
MonthArray(3)="May"
MonthArray(4)="April"
MonthArray(5)="June"
MonthArray(6)="July"
MonthArray(7)="August"
MonthArray(8)="September"
MonthArray(9)="October"
MonthArray(10)="November"
MonthArray(11)="December"
WHILE NOT RS.EOF
%>
<option value="<%
if BMCRepType="Monthly" then
response.write RS("ID")
else
response.write RS("Cat_ID")
end if
%>
">
<%
if BMCRepType="Monthly" then
FOR i=0 to UBOUND(MonthArray)
if (Month(RS("Cycle Month")))-1=i then
cycle=MonthArray(i)
end if
NEXT
response.write cycle & " " & Year(RS("Cycle Month"))
else
response.write RS("Cat_Name")
end if
%>
</option>
<%
RS.MoveNext
WEND
RS.Close
%>
</select></center></td>
</tr>
</table>
<input type="hidden" name="BMCRepType" value="<%=BMCRepType%>">
</form></center>
</body>






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Have Fun!
MaxOvrdrv2
on the second dropdown if statement change this lines
<%if request.querystring("id2")
with this
<%if request.querystring("id") <> "" then
And it will work just fine...
Happy programming...

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Does the changes that I had given to you does not work.
Regards,
gladmxl
it works now !
I'm sorry that I gave the points to another user,
blame me, because it's the first time (the first question)
I put on experts-exchange, not knowing that you can give points to only one person.
There is only one problem left:
the following code 'to keep the selected value' in every drop down menu doesn't work:
<%if request.querystring("id")=
Do you have an answer on this issue?
And if so, is there a way to give you points without posting a new question?
<%if request.querystring("id")=
works for me every time
MaxOvrdrv2






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Try to post a question with zero on the community support regarding the changes on this thread.
below is the link
https://www.experts-exchange.com/Community_Support/
<<<<<
There is only one problem left:
the following code 'to keep the selected value' in every drop down menu doesn't work:
<%if request.querystring("id")=
response.write "selected" end if%>
<<<<<<<
Actually the code that I had given is already a working code.
If possible try to check the rs("ID") and request.querystring("id") using response.write.
BTW how about the other two dropdown selected value is it fine.
Waiting for your reply...
gladxml
Also I will a moderator to review this question.
Regards,
gladxml

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
I posted a question for you at https://www.experts-exchange.com/questions/20506824/Points-for-gladxml.html
We usually try not to take points away from experts who received them without their own fault. And it lok sto me that m8rix participated in the solution of this problem quite a bit. The poinst for your question come out of my pocket, so nobody gets hurt :-)
Let me know if I can help you any further ... Good job, folks!
** Mindphaser - Community Support Moderator **
try it like this:
<%if request.querystring("id")=
works for me every time
MaxOvrdrv2
ASP
--
Questions
--
Followers
Top Experts
Active Server Pages (ASP) is Microsoft’s first server-side engine for dynamic web pages. ASP’s support of the Component Object Model (COM) enables it to access and use compiled libraries such as DLLs. It has been superseded by ASP.NET, but will be supported by Internet Information Services (IIS) through at least 2022.