This tutorial will show you how to build a dynamic select menu. The second drop down list depends on the value selected in the first drop down.
- Create a new page and build the following UI:
Both components are SelectMenu components
The first lists consists of: Fruits, Vegetables. Set the component name to: list1
The second list consists of: Orange, Apple, Banana. Set the component name to: list2 - Add Value Change event to the first list
- Add Run JavaScript to the event
- Add this JavaScript:
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('<option value="' + newData[i] + i + '">' + newData[i] + '</option>'); } dropDown.selectmenu('refresh'); - Test the app