Javascript - Redirect based on listbox selection


SUBMITTED BY: Guest

DATE: Sept. 23, 2013, 6:33 p.m.

FORMAT: JavaScript

SIZE: 1.3 kB

HITS: 1546

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title></title>
  5. <script>
  6. function setLink() {
  7. var linkBox = document.getElementById('linkBox');
  8. var selected = linkBox.options[linkBox.selectedIndex].value;
  9. switch (parseInt(selected)) {
  10. case 1:
  11. window.location = 'http://google.com';
  12. break;
  13. case 2:
  14. window.location = 'http://bing.com';
  15. break;
  16. case 3:
  17. window.location = 'http://yahoo.com';
  18. break;
  19. case 4:
  20. window.location = 'http://ask.com';
  21. break;
  22. default:
  23. break;
  24. }
  25. }
  26. </script>
  27. </head>
  28. <body>
  29. <select id="linkBox" onchange="setLink();">
  30. <option></option>
  31. <option value="1">Google</option>
  32. <option value="2">Bing</option>
  33. <option value="3">Yahoo</option>
  34. <option value="4">Ask</option>
  35. </select>
  36. </body>
  37. </html>

comments powered by Disqus