Click here to Skip to main content
15,943,148 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Experts,

I am doing an project. here i have used ajax JSON to transfer the datas.

I have two Dropdownlist . one is populate on Page load, and another is to populate in first dropdownlist selectchange .

i have used these all in ajax json method...

Here is the Below code that am used...

 $('#ddl_Standard').change(function () {

                    type: "POST",
                    url: "../../WebService.asmx/populate_Division",
                    dataType: "json",
                    data: JSON.stringify({ "Standard_ID": document.getElementById('ddl_Standard').value }),
                    contentType: "application/json; charset=utf-8",
                    success: function (json) {

                        var xmlDoc = "";
                        var xml = "";
                        xmlDoc = $.parseXML(json.d);
                        xml = $(xmlDoc);

                        $(xml).find("Table1").each(function () {
                            var Division_ID = $(this).find("Division_ID").text();
                            var Division = $(this).find("Division").text();
                            $("#ddl_Division").append("<option value='" + Division_ID + "'>" + Division + "</option>");



but it is not affecting.. Sometimes this code is working fine.. but some times it is not working... Can u please help me to solve this.

I have checked in Inspect Element and i can see the values are affected.. but not populated in dropdown control......

Thanks and Regards

Updated 4-Apr-13 22:35pm
Palash Mondal_ 5-Apr-13 3:25am    
Are you getting any value for the `Division_ID` & `Division` inside the each loop?
dilzz 5-Apr-13 3:27am    
yes i got the values.. i put an alert in that loop and checked... i got the values are correctly..

If you are using asp:DropDownList its possible that jQuery is not finding you element by it's ID("ddl_Division") due to webforms always messing with controls ID, to resolve this you could recover the element ClientID
var ddl_Division = <%= ddl_Division.ClientID %>

and in your script

$("#" + ddl_Division ).append("<option value='" + Division_ID + "'>" + Division + "</option>");

or you could add a class "dynamicPopulated" for an example to your dropdown and doing the append this way:

$(".dynamicPopulated").append("<option value='" + Division_ID + "'>" + Division + "</option>");
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900