This tutorial will show you how to build a dynamic drop down list feature. The second drop down list depends on the value selected in the first drop down.
- Create a new app and build the following simple UI:
Both components are SelectMenu components The first lists consists of: fruits, vegetables. Set the component name to typeList The second list consists of: orange, apple, banana. Set the component name to: dynamicList
- Add Value Change event to the first list
- Add Run Custom JavaScript to the event.
- Add the following JavaScript code:
var selectedValue = this.value;
var data = { 'fruits': ['orange', 'apple', 'banana'],
'vegetables': ['onion', 'carrot', 'tomato']
};
var dropDown = $('[name=dynamicList]');
dropDown.html('');
var newData = data[selectedValue];
for(i = 0; i < newData.length; i++) {
dropDown.append('<option value="' + newData[i] + i + '">' + newData[i] + '</option>');
}
dropDown.selectmenu('refresh');
- Test the app.
|
|