Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic List onChange

Status
Not open for further replies.

spirit66

Technical User
Apr 10, 2004
29
US
Hello!! This might be trivial for all the experts out there but i'm a newbie ,so please bear with me . I'm trying to create a dynamic drop list . I have the following code
<SELECT id="First" name="First" onchange="populate()">
<option value=""></option>
<%Code("//GETVALUES/")%>
</SELECT>

<SELECT id="second" name="second" >
<option value=""></option>
</SELECT>
As you see the values in "First" are obtained by using the ASP CODE <%Code("//GETVALUES/")%>.

Based on the value selected in "First" I need to populate "second" .
I'm curious how that populate() function needs to be written so that i can assign values to "Second" by calling another function similar to <%Code("//GETVALUES/")%>.
Thanks!

 
Hi...
OK, you have two combo boxes which you are filling the first one with you ASP function and, you want to fill the second one in the OnChange event of the first one...
you have two ways :
1- as you know, OnChange event, is a client side event handling of an object and in the populate() function, you don't have any access to youe DB or anything similar on the server, so in this way, the onliy solution which you have is to redirect to the same page and pass the value of the first combo box and in your code, check if the value is not empty, so then populate the second combo box :

if your page is named "MyPage" then you have this script :
Code:
    <script language="javascript">
      function populate(){
        window.location.href = 'MyPage.asp?fcmb=' + document.all.item('First).value;
      }
    </script>

and this part for your ASP code :
Code:
    <SELECT id="First" name="First" onchange="populate()">
      <option value=""></option>
      <%Code("//GETVALUES/")%>
    </SELECT>
    
    <SELECT id="second" name="second" >
      <option value=""></option>
      <%
      If Request.QueryString("fcmb") <> "" Then
        Code("//GET SECOND VALUES by using fcmb/")
      End If
      %>
    </SELECT>

2- also your second choice is that, if the number of the choices in the first combo box is limited and also the values of the second combo box are not a lot, you can load all the data in one page an then invisible all the combo boxes then in the onchange event, visible the required second combo box and invisible the last one or load all the data in a javascript variable(array) and in the onchange event, fill the second combo box with required records...

----
Harsh words break no bones but they do break hearts.
E.T.
 
I have a similar Problem.. I have a form that one drop down box is filled with static Values that the user can select.. and when the User selects a particular item in the first dropdown. then the second dropdown gets populated from a database table that gets all the records that match the value of the first dropdown..


I actually have a few dropdowns on the form that get populated from a database but I need this one to be dynamic based on user input.

any suggestions.. It seems like all the suggestions I have thus far have all been to reload the page based on the selection of the first dropdown.. but I don't know if thats the most effiecient way of doing this.

Thanks
Dean Forant
 
There are a few FAQs on this subject that should prove helpful, they cover the two major methods of doing dynamic dropdowns (i should know, I wrote one of them :p ). If you get stuck after looking through those, let us know.

-T

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
The never-completed website:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top