Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
    <!DOCTYPE html>
    <html>
    <head>
    <script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
      <meta charset="utf-8">
      <title>JS Bin</title>
    </head>
    <body>
    <select id="group">
      <option value="NONE">SELECT GROUP</option>
      <option value="A">A</option>
      <option value="B">B</option>
    </select>
      <select id="company"></select>
    </body>
    </html>
 
    var AA = new Array("1", "2");
    var BB = new Array("3", "4");
    var s = $("#company");
    $("#company").hide();
    /////// It works ///////
    $('#group').change(function(event){
       var optionName = $('#group').val();
       $("#company").show();
       switch(optionName){       
       case 'A':
           $('<option>').attr('value','NONE').text('A').appendTo(s);
           for(i=0; i<AA.length; i++)
             $('<option>').attr('value', AA[i]).text(AA[i]).appendTo(s);      
           break;
      case 'B':
           $('<option>').attr('value','NONE').text('B').appendTo(s);                 
           for(i=0; i<BB.length; i++)
            $('<option>').attr('value', BB[i]).text(BB[i]).appendTo(s);    
           break;
     }
    });
    ///// It doesn't work /////
    $("#company").change(function(event){
       alert($("#company").val());
    });
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
kursionpro
0viewers