Hi,
How do I add additional items on a dynamic select menu. I have used the following code which works for two labels, however, when i add a third label on list 1 and add the required labels on list 2 I get all the list 2 labels from the fruits. The list 1 vegetables works fine.
This cose works:
var selectedValue = this.value;
var data = { 'Fruits': ['Orange', 'Apple', 'Banana'],
'Vegetables': ['Onion', 'Carrot', 'Tomato']
};
var dropDown = $('[name=list2]');
dropDown.html('');
var newData = data[selectedValue];
for(i = 0; i < newData.length; i++) {
dropDown.append('' + newData + '');
}
dropDown.selectmenu('refresh');
When I try this it doesn't work as intended:
var selectedValue = this.value;
var data = { 'Fruits': ['Orange', 'Apple', 'Banana'],
'Vegetables': ['Onion', 'Carrot', 'Tomato'],
'Fish': ['Cod', 'Bass', 'Salmon'}
};
var dropDown = $('[name=list2]');
dropDown.html('');
var newData = data[selectedValue];
for(i = 0; i < newData.length; i++) {
dropDown.append('' + newData + '');
}
dropDown.selectmenu('refresh');
Can someone please assist and show how the code should be and why, it would really help with my understanding.
Regards
Richard
Also, are there any limitations to the number of list 1 labels you can add??
Thanks in advance!!!