Link to home
Create AccountLog in
ASP

ASP

--

Questions

--

Followers

Top Experts

Avatar of bburd
bburd

Dynamical 3-way drop down menu
I'm trying to program 3 drop down menus which are filled dynamically (in ASP) depending on the selection you make in the first, the second and the third drop down menu.

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.


Avatar of MaxOvrdrv2MaxOvrdrv2

i do... except it does not use JavaScript... it calls itself (the OnChange event calls the same .ASP page it's located in and passes it a value from which it changes the content of the second drop-down)...

so if you want it... i'd be glad to copy and paste it to you...

MaxOvrdrv2

Avatar of keystrokeskeystrokes🇺🇸

I am a little confused.

ASKER CERTIFIED SOLUTION
Avatar of m8rixm8rix🇦🇺

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


bburd,

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.


bburd,

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("ADODB.Connection")
oConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & dbPath & ";"

set rs = Server.CreateObject("ADODB.Recordset")
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='dropdown.asp?id=<%=rs("ID")%>'" <%if request.querystring("id")=rs("ID") then response.write "selected" end if%>><%=rs("ID")%></option>
<%
rs.movenext
loop
%>
</select>

<%if request.querystring("id2") <> "" then
set rs2 = Server.CreateObject("ADODB.Recordset")
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='dropdown.asp?id2=<%=rs1("ID")%>&amp;id=<%=request.querystring("id")%>'" <%if request.querystring("id2")=rs2("ID") then response.write "selected" end if%>><%=rs2("ID")%></option>
<%
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") <> "" then

set rs3 = Server.CreateObject("ADODB.Recordset")
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("ID")%> </option>
<%
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...


Avatar of bburdbburd

ASKER

gladxml,

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


Free T-shirt

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.


bburd,

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.Recordset")
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") <> "" then
set rs2 = Server.CreateObject("ADODB.Recordset")
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") <> "" then

set rs3 = Server.CreateObject("ADODB.Recordset")
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....




Avatar of bburdbburd

ASKER

gladxml,

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


 

bburd... you should specify a default populus for your drop downs.. that way they are always filled.. and then.. depending on the choices.. they get populated... but hey... rememebr i told you i had a way to do it in ASP.. well.. here's my code if you want a hint... works perfectly for me... it's just a 2 combo boxes... but 3 should utilise the same process... Enjoy! MaxOvrdrv2

---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.Document">
<link rel="stylesheet" type="text/css" href="fontcss.css">
<title>BMC Monthly Report</title>
</head>

<body>
<!-- #INCLUDE FILE="LeftMenu.inc" -->
<%
BMCRepType=TRIM(Request("BMCRepType"))
%>
<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?BMCRepType=<%=BMCRepType%>">
<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></td>
</tr>
<tr width="100%" height="50%" bgcolor="#0000FF">
      <td><center><select name="BMCRepType" size="1" onchange="SubmitForm(reptype)">
                  <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.Connection") 'open connection
Con.Open "filedsn=NewProjectTracking.dsn"                              'set DSN
Set RS = Server.CreateObject("ADODB.Recordset")            'open recordset
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></center>
      <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></td>
</tr>
<tr width="100%" height="50%" bgcolor="#0000FF">
<td><center><select name="cmonth" size="1" onChange="window.open('ProduceBMC-M-Report.asp?BMCRepType=<%=BMCRepType%>&amp;cmonth='+document.month.cmonth.value);">
      <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>




Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


to make it work for you... simply change the "SubmitForm(whatever)" in the onChange events to: "JavaScript: document.FormNameHere.submit();"

Have Fun!

MaxOvrdrv2

bburd,

on the second dropdown if statement change this lines

<%if request.querystring("id2") <> "" then

with this


<%if request.querystring("id") <> "" then

And it will work just fine...

Happy programming...





Avatar of bburdbburd

ASKER

Thx for the solution !

Free T-shirt

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.


bburd,

Does the changes that I had given to you does not work.

Regards,
gladmxl

Avatar of bburdbburd

ASKER

gladxml,

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")=rs("ID") then response.write "selected" end if%>

Do you have an answer on this issue?
And if so, is there a way to give you points without posting a new question?

try it like this:

<%if request.querystring("id")=rs("ID") then%>SELECTED<%end if%>

works for me every time

MaxOvrdrv2

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


bburd,

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/

bburd,

<<<<<
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")=rs("ID") then
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


bburd,

Also I will a moderator to review this question.

Regards,
gladxml

Free T-shirt

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.


gladxml

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

XML... i told you already how to select from previous choices... no response.write object... just this::

try it like this:

<%if request.querystring("id")=rs("ID") then%>SELECTED<%end if%>

works for me every time

MaxOvrdrv2
ASP

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.