Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {"beverages":["Coffee","Coke"],"snacks":["Chips","Cookies"]}
- <script type="application/javascript">
- $("#first-choice").change(function() {
- var $dropdown = $(this);
- $.getJSON("../../getdata.php?getDropdown=yes&people_no=1", function(data) {
- var key = $dropdown.val();
- var vals = [];
- switch(key) {
- case 'beverages':
- vals = data.beverages;
- break;
- case 'snacks':
- vals = data.snacks;
- break;
- case 'base':
- vals = ['Please choose from above'];
- }
- var $secondChoice = $("#second-choice");
- $secondChoice.empty();
- $.each(vals, function(index, value) {
- $secondChoice("<option>" + value + "</option>");
- });
- });
- });
- </script>
- <select id="first-choice">
- <option selected value="base">Please Select</option>
- <option value="beverages">Beverages</option>
- <option value="snacks">Snacks</option>
- </select>
- <br />
- <select id="second-choice">
- <option>Please choose from above</option>
- </select>
- vals = data.beverages;
- $secondChoice.append("<option>" + value + "</option>");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement