Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. {"beverages":["Coffee","Coke"],"snacks":["Chips","Cookies"]}
  2.  
  3. <script type="application/javascript">
  4. $("#first-choice").change(function() {
  5.  
  6. var $dropdown = $(this);
  7.  
  8. $.getJSON("../../getdata.php?getDropdown=yes&people_no=1", function(data) {
  9.  
  10. var key = $dropdown.val();
  11. var vals = [];
  12.  
  13. switch(key) {
  14. case 'beverages':
  15. vals = data.beverages;
  16. break;
  17. case 'snacks':
  18. vals = data.snacks;
  19. break;
  20. case 'base':
  21. vals = ['Please choose from above'];
  22. }
  23.  
  24. var $secondChoice = $("#second-choice");
  25. $secondChoice.empty();
  26. $.each(vals, function(index, value) {
  27. $secondChoice("<option>" + value + "</option>");
  28. });
  29.  
  30. });
  31. });
  32. </script>
  33.  
  34. <select id="first-choice">
  35. <option selected value="base">Please Select</option>
  36. <option value="beverages">Beverages</option>
  37. <option value="snacks">Snacks</option>
  38. </select>
  39.  
  40. <br />
  41.  
  42. <select id="second-choice">
  43. <option>Please choose from above</option>
  44. </select>
  45.  
  46. vals = data.beverages;
  47.  
  48. $secondChoice.append("<option>" + value + "</option>");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement