Link to home
Start Free TrialLog in
Avatar of general_deta
general_deta

asked on

asp dynamic pulldown menu

Hi, here is what my asp code looks like:

 <%
dim conn, strconn, SQL, objrs
SQL = "SELECT * FROM [db] order by id"
SQL2 = "SELECT * FROM [db2] order by id"
SQL3 = "SELECT * FROM [db3] order by id"
strConn= "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("../Data/db.mdb")
set conn = server.createobject("adodb.connection")
conn.open strconn

%>
 

<form method="post" action="stockcosts2.asp" name="form1">
  <blockquote>
    <p class="style1 style2">Bought:
      <select name="bought" class="style2">
        <%

set objrs=conn.execute(SQL2)
set objrs2=conn.execute(SQL)
set objrs3=conn.execute(SQL3)
Do While not objRS.EOF
%>    
        <option value="<%=objrs("bought")%>" selected><%=objrs("bought")%></option>
     
    <%
objRS.MoveNext
loop

%>      
     
  </select>

It basically has three pull down menus, and the content within are taken from a database.  the table within the database has 4 fields.  bought, date, sold, cost.  You can view it at www.indavis.com/_private/stockcosts.asp

I was wondering for the first pull down menu "bought", is it possible that for example if I selected ATT, the next two pull down menus will have content that only pertains to records that have ATT?  So initially the users chooses the stock in the bought pulldown menu, and once he/she selected a certain stock, ie ATT, the next two pull down menus will have ....Date   two options, 1/1/11 and 1/2/03   and   Sold  two options, DTD, and DTC.   Thanks!

A

Database:

Bought      Date     Sold     Cost
ATT          1/1/11    DTD     1
ATT         1/2/03    DTC      2
FBB          3/3/3      JJ        3
FBB         3/3/2      jj           5
Avatar of cakirfatih
cakirfatih

general deta,
what you are trying is possible !
your SQL2 and SQL3 will have to contain conditions !
for exmaple you defined SQL2 = "SELECT * FROM [db2]"
you will have to define it after the user's selction of the "bought" drop down
then : SQL2 = SQL2 & " Where bought ='" & bought_value_from_dropdown1 &"'"

The you do the same for SQL3.
hope this helps.
ASKER CERTIFIED SOLUTION
Avatar of alorentz
alorentz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of general_deta

ASKER

cool, i get what you are saying, so pretty much make an iframe/frame and create a javascript that will post to it self which a set of given conditions.  Can you show me an example of a javascript that will post to itself once a pull down menu content is selected?  Thanks for the fast response!
HELL NO!  No frames EVER....heh,heh.  I'm adament about no frames!


Yes, you use Javascript to post the page to itself, howerver you don't need frames to do this.


ie.
<%
if request("dropdown1") <> "" then
SQL2 = "SELECT * FROM [db2] where somefield = '" & dropdown1 & "' order by id"
else
SQL2 = "SELECT * FROM [db2] order by id"
end if
%>


<FORM action="" method=POST id=form1 name=form1>
<select name=dropdown1 onchange="javascript:document.form1.submit();">
       <option value="ATT">ATT</option>
</select>
</form>

etc...
cool, its partially working now.  Just a quick question, for example if i select FBB under the pull down menu, once it refreshed and submit the data, the pull down menu still shows the first selection ATT, how do i make it highlight FBB, but still have all the rest under the menu?  and also, whats the code to skip duplicate records?  IE

   <%

set objrs=conn.execute(SQL2)
Do While not objRS.EOF
%>    
        <option value="<%=objrs("bought")%>" selected><%=objrs("bought")%></option>
     
    <%
objRS.MoveNext
loop

%>      
     
and skip duplicate records? for example just only show one "ATT" and not 3 identical ones?
<%

set objrs=conn.execute(SQL2)
Do While not objRS.EOF
  if objrs("bought") = request("dropdown1") then
     val = " selected"
  else
     val = "" 
  end if
%>    
        <option value="<%=objrs("bought") & val%>"><%=objrs("bought")%></option>
     
    <%
objRS.MoveNext
loop

%>      
thanks for your help!!

btw, how do i skip idential records?  IE the pull down menu shows two ATT but i only want it to show one
That's what the code I just gave you does, with minor correction:

<%

set objrs=conn.execute(SQL2)
Do While not objRS.EOF
  if objrs("bought") = request("dropdown1") then
     val = " selected"
  else
     val = "" 
  end if
%>    
        <option value="<%=objrs("bought")%>" <%=val%>><%=objrs("bought")%></option>
     
    <%
objRS.MoveNext
loop

%>    
right, this code selects it correctly, however, the pull down menu still shows multiple duplicate records.