0

I have an array which is inside some object.How can I bind object to the combobox list .

Combobox code:

 <select name="select-native-5" id="cmbDty"></select>

I need to bind Id and Ad field to the combobox

and my array object; enter image description here

here is the how I get the object array,

Jquery Code:

 $("#select-native-11").change(function () {
               var dd = $("#select-native-11").val();
                $.ajax({
                type: "POST",
                url: "MasaSiparis.aspx/AltMenuGetir2",
                data: "{'p':'" + dd + "'}",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                    alert(data.d);
                        $.each(data.d, function (val, text) {
                        alert(val);
                       //I need to put here 
                        });
                });
                    },
                error: function () { alert('HATA');}
            });
        });

2 Answers 2

1

you need to get a reference of your dropdownlist and add option in your dropdown..

 $("#select-native-11").change(function () {
                   var dd = $("#select-native-11").val();
                    $.ajax({
                    type: "POST",
                    url: "MasaSiparis.aspx/AltMenuGetir2",
                    data: "{'p':'" + dd + "'}",
                    dataType: "json",
                    contentType: "application/json; charset=utf-8",
                    success: function (data) {
                        alert(data.d);
var x = document.getElementById("mySelect");
                            $.each(data.d, function (val, text) {
                            alert(val);
                           //I need to put here 
                          //here is your dropdownid replace with "select"

                          var option = document.createElement("option");
                          option.text = text;
                          option.value = val;
                          x.add(option);

                            });
                    });
                        },
                    error: function () { alert('HATA');}
                });
            });
Sign up to request clarification or add additional context in comments.

Comments

0

here is the solution ;

$.ajax({
                type: "POST",
                url: "MasaSiparis.aspx/AltMenuGetir2",
                data: "{'p':'" + dd + "'}",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function (data) {

                    var x = document.getElementById("select-native-5");
                    for (var i = 0; i < data.d.length; i++) {
                        //alert(data.d[i]); //"aa", "bb"

                        var option = document.createElement("option");
                        for (var key in data.d[i]) {
                           alert(key + ': ' + data.d[i][key]);

                            if (key == "AltMenuId") {
                                option.value = data.d[i][key];
                            }

                            if (key == "Ad") {
                                option.text = data.d[i][key];
                            }

                        }
                        x.add(option);
                    }

                },
                error: function () { alert('HATA'); }
            });

*key point is loop throug properly

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.