code_junkie

Simple javascript only working in FireFox

Nov 14th, 2011
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. <script type="text/javascript">
  2. function display_year2(start_year) {
  3. //alert(start_year);
  4. if (start_year != "Any") {
  5. var i;
  6. for(i=document.form.year2.options.length-1;i>=0;i--)
  7. {
  8. document.form.year2.remove(i);
  9. }
  10.  
  11. var x = 2009;
  12. while (x >= start_year) {
  13. var optn = document.createElement("OPTION");
  14. optn.text = x;
  15. optn.value = x;
  16. document.form.year2.options.add(optn);
  17. //alert(x);
  18. x--;
  19. }
  20. }
  21. else
  22. {
  23. var i;
  24. for(i=document.form.year2.options.length-1;i>=0;i--)
  25. {
  26. document.form.year2.remove(i);
  27. }
  28. var optn = document.createElement("OPTION");
  29. optn.text = "Any";
  30. optn.value = "Any";
  31. document.form.year2.options.add(optn);
  32. } // end else
  33. } // end function
  34. </script>
  35.  
  36. <select name="year1" id="year1">
  37. <option value="Any" onclick="javascript:display_year2('Any');" >Any</option>
  38. <option value="2009" onclick="javascript:display_year2(2009);" >2009</option>
  39. <option value="2008" onclick="javascript:display_year2(2008);" >2008</option>
  40. </select>
  41.  
  42. <select name="year1" id="year1" onchange="javascript:display_year2(this.options[this.selectedIndex].value)">
  43. <option value="Any">Any</option>
  44. <option value="2009">2009</option>
  45. <option value="2008">2008</option>
  46. </select>
  47.  
  48. <OPTION onclick=javascript:display_year2(2009); value=2009>
  49.  
  50. <select onchange="display_year2(this.options[this.selectedIndex].value)">
  51. <option value="2009">2009</option>
  52. ...
  53. </select>
  54.  
  55. var i;
  56. for(i=document.form.year2.options.length-1;i>=0;i--)
  57. {
  58. document.form.year2.remove(i);
  59. }
  60.  
  61. var year2= document.getElementById('year2');
  62. year2.options.length= 0;
  63.  
  64. var optn = document.createElement("OPTION");
  65. optn.text = x;
  66. optn.value = x;
  67. document.form.year2.options.add(optn);
  68.  
  69. year2.options[year2.options.length]= new Option(x, x);
Add Comment
Please, Sign In to add comment