R34P3D

Untitled

Nov 2nd, 2012
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.12 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <title>OnChange</title>    
  5.     </head>
  6.     <body>
  7.         <div>
  8.             <form action="" method="post">
  9.                 <div>
  10.                     Select:
  11.                     <select name="firstSelect" id="firstSelect">
  12.                         <option value="Subject1,Subject2,Subject3">Subject 1 - 3</option>
  13.                         <option value="Subject4,Subject5,Subject6">Subject 3 - 6</option>
  14.                         <option value="Subject7,Subject8,Subject9">Subject 7 - 9</option>
  15.                         <option value="Subject10,Subject11,Subject12">Subject 10 - 12</option>
  16.                     </select>
  17.                 </div>
  18.                 <div>
  19.                     <select name="secondSelect" id="secondSelect">             
  20.                     </select>
  21.                 </div>
  22.             </form>
  23.         </div>
  24.        
  25.         <!-- Scripts -->
  26.         <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
  27.         <script>
  28.             $("#firstSelect").change(function() {
  29.                 alert("a");
  30.                 $("#secondSelect").html("");
  31.                 var selectedOption = $("#firstSelect").val();
  32.                 var options = selectedOption.split(",");
  33.                 for(var i = 0; i < options.length; i++) {
  34.                     $("#secondSelect").append("<option value="+options[i]+">"+options[i]+"</option>");
  35.                 }
  36.             });
  37.         </script>
  38.     </body>
  39. </html>
Advertisement
Add Comment
Please, Sign In to add comment