javascript - My second script with a dropdown-list doesn't work -


this question has answer here:

hi. i'm new here. , i'm not in english.

i've got problem in code.

step 1.
made first dropdown list.

step 2.
second dropdown list created when first dropdown list value changed.

step 3.
alert msg should shown when selected value of second dropdown list changed.

step1,2 ok step 3 not.

please give me way solve problem. thanks!

html

<select id="group"> <option value="none">select group</option> <option value="a">a</option> <option value="b">b</option> </select> 

script

/////// works /////// $('#group').change(function(event){     var optionname = $('#group').val();    var aa = new array("1", "2");    var bb = new array("3", "4");     switch(optionname){           case 'a':        $('#company').remove().end();        var s= $('<select ></select>').attr('id','company');         $('<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);                      s.appendto('body');        break;    case 'b':        $('#company').remove().end();        var s= $('<select></select>').attr('id','company');        $('<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);                   s.appendto('body');        break;  default:        $('#company').remove().end();        break;  } });  ///// doesn't work ///// $('#company').change(function(event){    alert($('#company').val()); }); 

maybe this:

html <!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>   javascript   var aa = new array("1", "2"); var bb = new array("3", "4"); var s = $("#company");  $("#company").hide();  /////// 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;  } });  ///// doesn't work ///// $("#company").change(function(event){    alert($("#company").val()); }); 

https://jsbin.com/bisena/edit?html,js,console,output


Comments

Popular posts from this blog

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Using jquery append to add option values into a select element not working -

javascript - Restarting Supervisor and effect on FlaskSocketIO -