By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,466 Members | 1,148 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,466 IT Pros & Developers. It's quick & easy.

Dependent Drop Down Box

P: 31
HI,

I have 2 drop down box in my form in ASP named DD1 and DD2.

I would like to choose one option in DD1 and based on what I choosed in that, the second drop down (DD2) would be refreshed and show some special informations in it!

basically I want to be able to pass whatever I choosed in DD1 to DD2 and based on that, run a special store procedure!

I have no idea how should I do it! Would you please help me?

Regards,
Faranak
Jun 6 '08 #1
Share this Question
Share on Google+
5 Replies


idsanjeev
100+
P: 241
you have to use onchange event
like onChange="this.form.submit();
Try
Expand|Select|Wrap|Line Numbers
  1. <tr><td>field1</td>
  2.    <th width=5%>:</th>
  3. <td>
  4. <% Set RS3=con.Execute("select *from table where field='"&field1&"'") %>
  5.         <select Id="field1" Name="field1" onChange="this.form.submit();">
  6.         <option value="ALL">[Select]</option>
  7.             <% while not rs3.eof %>
  8.         <option value=<%=rs3("field1")%>><%=rs3("field1")%></option>
  9.             <%
  10.             rs3.movenext
  11.             wend
  12.             Rs3.close
  13.             session("field1")=Request.Form("field1")
  14.             if SEssion("field1")<>"" then
  15.  
  16.            Set RS3=con.Execute("select *from table where deptcode='"&session("field1")&"'")            %>
  17.         <option value=<%=rs3("field1")%> selected ><%=rs3("field1")%></option>
  18.          <%end if%>    
  19.          </select></td>
  20.          </tr>
  21.  
  22.            <tr>
  23.     <td width=15%> <font  color="#0000FF"><b>Field2 </td>
  24.     <th width=5%>:</th>
  25.     <td>
  26. <%    
  27.             Set RS=CON.Execute("select * from table where field='"&session("field1")&"'" )
  28.  
  29.             %>
  30.  
  31.         <select Id="Sect" Name="sect" onChange="this.form.submit();">
  32.         <option value="ALL">[Select field2]</option>
  33.             <% while not rs.eof %>
  34.         <option value=<%=rs("field2")%> ><%=rs("field2")%></option>
  35.         </option>
  36.             <%
  37.             rs.movenext
  38.             wend
  39.             Rs.close
  40.             session("field2")=Request.Form("field2")
  41.             if SEssion("field1")<>"" then
  42.             IF session("field2")<>"ALL" THEN
  43.  
  44.            Set RS=con.Execute("select *from table where  field='"&session("field2")&"' ")            %>
  45.         <option value=<%=rs("field2")%> selected ><%=rs("field2")%></option>
  46.          <%
  47.          end if
  48.          end if
  49.             %>    
  50.          </select></td>
  51.          </tr>

Regards
jha
Jun 6 '08 #2

jeffstl
Expert 100+
P: 432
You can also use javascript to do it if you aren't working with databases to populate the drop downs and you just want them hard coded selections.

Post on javascript drop down population
Jun 6 '08 #3

P: 31
Hello,

I appreciate your response.

The section onChange="this.form.submit(); doesn't refresh my form! do I need to write a JavaScirpt function?

Regards,
FF
Jun 7 '08 #4

idsanjeev
100+
P: 241
Hello,
The section onChange="this.form.submit(); doesn't refresh my form! do I need to write a JavaScirpt function?
i think you haven't use code within form tag so it doesn't refresh your form so
try
Expand|Select|Wrap|Line Numbers
  1. <form action="yourcurrentpage.asp" method="post">
  2. <!--code postted above-->
  3. <!-- close form tag-->
  4. </form>
you can use javascript to
regards
Jha
Jun 7 '08 #5

Expert 100+
P: 145
Hello,

I appreciate your response.

The section onChange="this.form.submit(); doesn't refresh my form! do I need to write a JavaScirpt function?

Regards,
FF

That could be a browser issue. Try:

onChange="getElementById('myFormId').submit();"

where myFormId is the tag id of your <form> element:

[HTML]<form id='frmSubmitInfo' action='go.asp' method='Post'>[/HTML]

that line works well with FireFox and IE.
Jun 16 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.