简体   繁体   中英

jquery won't work in multi level dependency?

$(document).ready(function() { 

     $("#ddlprod").change(function() {

        var pk= $("#ddlprod").val();

        $.ajax({

        url: "ajaxprintdropdown.php",

        type: "POST",

        data: 'pk='+pk,

        timeout: 5000,

        success:  function(output) {                            

            $('#divtesting').show();    //works well            
            $('#divtesting').html(output);   //works well
        },


        }); 


     $("#ddltesting").change(function(){
        alert('a');    //not functioning at all
        var c= $("#ddltesting").val();
        alert(c);   //not functioning at all    
      });



     });

ajaxprintdropdown.php's output

<select name=ddltesting id=ddltesting >
<option value=''>--Select--</option>
<option value='test1'>bla for test1</option>
<option value='test2'>bla for test2</option>
</select>

Jquery not working for multi level dependency? $("#ddltesting").change(function(){ no response at all

Edit

@altCognito pointed out that live works with change events also. Then you can write

$("#ddltesting").live("change",function(){
    alert('a');    
    var c= $("#ddltesting").val();
    alert(c);   
});

From jQuery 1.4 Released

The change and submit events work reliably across browsers for both normal and live events. We override the normal change and submit events in Internet Explorer and replace them with events that work identically to the other browsers.

Try

$("#sampletextbox").val(c);

instead of

$("#sampletextbox").text(c);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM