I want to populate a SELECT Dropdown List with JSON Data using JavaScript
success: function(data) {
var distList = data.d;
console.log(distList);
//consoleoutput = [{ "Districtname": "CENTRAL DELHI", "ID": 1 }, { "Districtname": "NORTH DELHI", "ID": 2 }, { "Districtname": "NORTH EAST DELHI", "ID": 3 }, { "Districtname": "NORTH WEST DELHI", "ID": 4 }, { "Districtname": "SOUTH DELHI", "ID": 5 }, { "Districtname": "SOUTH EAST DELHI", "ID": 6 }, { "Districtname": "SOUTH WEST DELHI", "ID": 7 }, { "Districtname": "WEST DELHI", "ID": 8 }]
var s = '';
for (var i = 0; i < distList.length; i++) {
s += '';
}
$("#dist").html(s);
}
i tried another approach
$.each(distList, function (key, value) {
$('#dist').append('');
});
but
Uncaught TypeError: Cannot use 'in' operator to search for 'length' in [{"Districtname":"CENTRAL.................... ,{"Districtname":"WEST DELHI","ID":8}]
plz help

Muzaffar Ur RahmanPosted Nov 23, 2023, 5:39 AM
Hi, Could you please have look on this articel.
https://checkedexception.com/blog/populate-a-select-dropdown-list-with-json
Amit MohantyPosted Nov 23, 2023, 6:19 AM
You can also try this to set value as well as text.
Khushi Soni RajpootPosted Nov 23, 2023, 5:55 AM
i solve this