Solved

Dynamic Filter of ddlistbox

Posted on 2001-06-04
2
154 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

911 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

25 Experts available now in Live!

Get 1:1 Help Now