Jquery dynamic dropdown event not firing

Posted by kevin on Stack Overflow See other posts from Stack Overflow or by kevin
Published on 2010-04-22T11:24:35Z Indexed on 2010/04/22 12:13 UTC
Read the original article Hit count: 140

Filed under:
|

Hi i am trying to create dropdownlists dynamically and populating the contents via an ajax call, this sort of works in the sense that the drop down is created and populated as required but its 'change' event does not fire. I am posting the code below, if anyone can spot something obvious, can you please let me know regards

$(document).ready(function () {

    $("#positions select").change(function (e) {
        alert("in");
        var id = $("#category_id").val();
        $.getJSON("/Category/GetSubCategories/" + id, function (data) {
            if (data.length > 0) {

                alert(data.length);
                var position = document.getElementById('positions');
                var tr = position.insertRow(7);
                var td1 = tr.insertCell(-1);
                var td = tr.insertCell(-1);
                var sel = document.createElement("select");
                sel.name = 'sel';
                sel.id = 'sel';
                sel.setAttribute('class', 'category');



                td.appendChild(sel);
                $.each(data, function (GetSubCatergories, category) {
                    $('#sel').append($("<option></option>").
           attr("value", category.category_id).
          text(category.name));

                });
            }



        });
    });
}); 

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript