Solved

Dynamic Filter of ddlistbox

Posted on 2001-06-04
2
159 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

733 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