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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dropdown with multiple selection sets

Status
Not open for further replies.

crabgrass

Technical User
Aug 29, 2007
111
US
I have a page with a radio button option group consisting of 2 buttons. There is also a dropdown select, the available options of which will be based on the user's choice in the radio group. I have a js that will do this based on arrays of the possible choices for the select. These arrays are hardcoded in the function.

My problem is that I want the select option choices to be soft coded and drawn from a table via an sql query so the arrays would be built dynamically when the page is loaded.

Can someone tell me how to do this? or is there another alternative for changing the options in the select?

Thanks
 
or is there another alternative for changing the options in the select?

If you have never used AJAX before, now is the time. I'd suggest doing a google search on "AJAX tutorial" to read up on the concept.

Basically what you're going to want to do is code is so that when one of the radio buttons is clicked, AJAX fires off a new page that queries the database to get the available options for your dropdown. When the output is returned from AJAX, use javascript to populate the data.

There are likely loads of examples out on the web on how to do this. Let us know if you have trouble finding what you're looking for.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Thanks. I could reload the page with plain asp but I was hoping to avoid another trip to the server.
 
I could reload the page with plain asp but I was hoping to avoid another trip to the server.

With AJAX you aren't reloading the page though. You're making a trip to the server to pull a very small amount of information, and then using javascript to make the appropriate changes.

As an alternative, you could just load all possibilities for your radio buttons when the page initially loads, and then save those possibilities into client side arrays. Then, when the radio button is clicked, load the <select> with the information from the array. For your scenario this probably wouldn't be a bad solution because you only have 2 radio buttons. This makes a small subset of possiblities for your <select> box.

But... imagine if you had 100 radio buttons. That means that you'd have to load in 100 different possible arrays of options for the <select> box. That's a lot of unnecessary strain on the server, and bandwidth wasted. In this instance, it's much more desirable to pull the subset of data when they click on each radio button. It's likely that they'll only be clicking a radio button once or twice on the page, so that means you'd be pulling 2 or 3 sets of possible arrays instead of all 100.

You're free to design this however you'd like, but from a professional standpoint I think it would be beneficial for you to use AJAX for this. Even more so if you've never used it before because that will give you another tool under your belt. AJAX can be used for loads of things, but this is a very simple example that could help you to get your feet wet.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top