Advertisement
Guest User

jquery select

a guest
Mar 28th, 2014
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.16 KB | None | 0 0
  1. <html>
  2.     <head>
  3.         <script src="jquery/jquery-1.11.0.min.js" type="text/javascript"></script>
  4.     </head>
  5.     <body>
  6.         <select id="test1" blaat="#test2" class="vervolg">
  7.             <option value="1">Linux</option>
  8.             <option value="2">Microsoft</option>
  9.             <option value="3">Apple</option>
  10.         </select>
  11.  
  12.         <select id="test2" blaat="#test3" class="vervolg">
  13.         </select>
  14.  
  15.         <select id="test3">
  16.         </select>
  17.  
  18.         <script>
  19.             function setChildForSelectbox(selectId,selectedValue,child){
  20.                 $.get("json/" + selectId + "/" + selectedValue, function(data){
  21.                     // console.log(data[0].desc);
  22.                     console.log("setup " + child + " met gekozen optie " + selectedValue)
  23.                     var sel = $(child);
  24.                     sel.empty();
  25.                     for (var i=0; i <data.length; i++) {
  26.                        if (i==0){
  27.                            sel.append('<option value="' + data[i].id + '" selected>' + data[i].desc + '</option>');
  28.                         }else{
  29.                             sel.append('<option value="' + data[i].id + '">' + data[i].desc + '</option>');
  30.                         }
  31.                     }
  32.                     // console.log("Standaard gekozen : " + sel.find("option:selected").attr("value"));
  33.                     selectionReady(child);
  34.                 }, "json")
  35.                     .fail( function() {
  36.                         console.log("Foutje bij laden JSON!");
  37.                     });
  38.             }
  39.  
  40.             function selectionReady(child){
  41.                 if($(child).attr('blaat') !== undefined){
  42.                     id = $(child).attr('id');
  43.                     selected = $(child).find("option:selected").attr("value");
  44.                     child = $(child).attr('blaat');
  45.                     setChildForSelectbox(id,selected,child);
  46.                 }
  47.             }
  48.  
  49.             $(document).ready(function() {
  50.                 $(".vervolg").change(function(){
  51.                     selectionReady("#" + $(this).attr('id'));
  52.                 });
  53.             });
  54.         </script>
  55.     </body>
  56. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement