Solved

Dynamic Filter of ddlistbox

Posted on 2001-06-04
2
152 Views
Last Modified: 2012-08-13
What's the easiest way to filter a Dropdown listbox based on the value of another listbox without having to submit the form?  Is there an easier way than using div statements?

Example:

Listbox A is a list of stores. "S1", "S2", etc...
Listbox B is a list of products for a store "S1P1", "S1P2", "S2P1", S2P2", etc....

I want to retrieve all of the products when the page is accessed but I want to filter the list based on which store is selected in Listbox A.

Thanks
0
Comment
Question by:lavesa
  • 2
2 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 50 total points
ID: 6154108
<script>
function setVal(theSel) {
   if (theSel.selectedIndex < 1) return;
   storeSel = theSel.form.store;
   prods = theSel.options[theSel.selectedIndex].value.split('|')
   for (i=0;i<prods.length;i++) {
      storeSel.options[i+1] = new Option(prods[i],prods[i]);
   }
}
</script>
<form>
<select onChange="setVal(this)"><
<option value="">Select store
<option value="P1|P2">Store 1</option>
<option value="P2|P3">Store 2</option>
</select>
<selectname="store">
<option value="">Select Product
<option>__________________</option>
<option>__________________</option>
</select>
</form>
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6154113
You can also store the values in arrays and access them directly without using the split method
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now