Dependent Drop Down Box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • F159753
    New Member
    • Apr 2008
    • 31

    Dependent Drop Down Box

    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
  • idsanjeev
    New Member
    • Oct 2007
    • 241

    #2
    you have to use onchange event
    like onChange="this. form.submit();
    Try
    Code:
    <tr><td>field1</td>
       <th width=5%>:</th>
    <td>
    <% Set RS3=con.Execute("select *from table where field='"&field1&"'") %>
        	<select Id="field1" Name="field1" onChange="this.form.submit();">
            <option value="ALL">[Select]</option>
    			<% while not rs3.eof %>
    		<option value=<%=rs3("field1")%>><%=rs3("field1")%></option>
    			<%
    			rs3.movenext
    			wend
    			Rs3.close
    			session("field1")=Request.Form("field1")
    			if SEssion("field1")<>"" then
    			
    	       Set RS3=con.Execute("select *from table where deptcode='"&session("field1")&"'")			%>
    		<option value=<%=rs3("field1")%> selected ><%=rs3("field1")%></option>
             <%end if%>	
             </select></td>
    		 </tr>
    		 
    		   <tr>
        <td width=15%> <font  color="#0000FF"><b>Field2 </td>
    	<th width=5%>:</th>
        <td>
    <%	
    			Set RS=CON.Execute("select * from table where field='"&session("field1")&"'" )
    
    			%>
    
        	<select Id="Sect" Name="sect" onChange="this.form.submit();">
            <option value="ALL">[Select field2]</option>
    			<% while not rs.eof %>
    		<option value=<%=rs("field2")%> ><%=rs("field2")%></option>
    		</option>
    			<%
    			rs.movenext
    			wend
                Rs.close
    			session("field2")=Request.Form("field2")
    			if SEssion("field1")<>"" then
    			IF session("field2")<>"ALL" THEN
    			
    	       Set RS=con.Execute("select *from table where  field='"&session("field2")&"' ")			%>
    		<option value=<%=rs("field2")%> selected ><%=rs("field2")%></option>
             <%
    		 end if
    		 end if
    			%>	
             </select></td>
    		 </tr>

    Regards
    jha

    Comment

    • jeffstl
      Recognized Expert Contributor
      • Feb 2008
      • 432

      #3
      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

      Comment

      • F159753
        New Member
        • Apr 2008
        • 31

        #4
        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

        Comment

        • idsanjeev
          New Member
          • Oct 2007
          • 241

          #5
          Originally posted by F159753
          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
          Code:
          <form action="yourcurrentpage.asp" method="post">
          <!--code postted above-->
          <!-- close form tag-->
          </form>
          you can use javascript to
          regards
          Jha

          Comment

          • Jerry Winston
            Recognized Expert New Member
            • Jun 2008
            • 145

            #6
            Originally posted by F159753
            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="getEl ementById('myFo rmId').submit() ;"

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

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

            that line works well with FireFox and IE.

            Comment

            Working...