Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title></title>
  6. </head>
  7. <body>
  8. <form id="picker" action="" method="post">
  9. <select id="state">
  10. <option value="">--</option>
  11. <option value="MO">Missouri</option>
  12. <option value="WA">Washington</option>
  13. <option value="CA">California</option>
  14. </select>
  15. <select id="cities">
  16. </select>
  17. </form>
  18.  
  19. <script>
  20. var citystore = new Array();
  21. citystore[0] = ["CA", "San Francisco"];
  22. citystore[1] = ["CA", "Los Angeles"];
  23. citystore[2] = ["CA", "San Diego"];
  24. citystore[3] = ["MO", "St. Louis"];
  25. citystore[4] = ["MO", "Kansas City"];
  26. citystore[5] = ["WA", "Seattle"];
  27. citystore[6] = ["WA", "Spokane"];
  28. citystore[7] = ["WA", "Redmond"];
  29.  
  30. window.onload = function() {
  31. document.getElementById("state").onchange = filterCities;
  32. };
  33.  
  34. function filterCities() {
  35. var state = this.value;
  36. var city = document.getElementById("cities");
  37. city.options.length = 0;
  38.  
  39. for (var i = 0; i < citystore.length; i++) {
  40. var st = citystore[i][0];
  41.  
  42. if (st == state) {
  43. var opt = new Option(citystore[i][1]);
  44. try {
  45. city.add(opt, null);
  46. } catch (e) {
  47. city.add(opt);
  48. }
  49. }
  50. }
  51. }
  52. </script>
  53. </body>
  54. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement