Populate Dropdown Listbox based on another Listbox
I have the following select dropdowns:
- <select name="a" id="a">
- <option value="">Select Something</option>
- <option value="1">a1</option>
- <option value="2">a2</option>
- <option value="3">a3</option>
- </select>
- <select name="b" id="b"></select>
I use the following associative array (object?) to designate which values I would like displayed depending on whether a1, a2 or a3 is selected from the first dropdown:
- var somearray = [
- {
- "a1" : ['a1.1']
- },
- {
- "a2" : ['a2.1','a2.2']
- },
- {
- "a3" : ['a3.1','a3.2','a3.3', 'a3.4']
- }
- ] ;
I'm not sure what I need to do next. I tried the following, and it loops through with the "name", which is 0, 1, 2, but not the value:
- $.each(somearray, function(name,value) {
- $(":input[name='" + name + "']").val(value);
- alert("test: " + name + value);
- });
Is the array correctly defined? Am I way off by using .each to populate the select listbox? Thanks for any pointers.