I wrote this little function to populate the drop-down list with data from the server.
function fillDropDown(url, dropdown) { $.ajax({ url: url, dataType: "json" }).done(function (data) { // Clear drop down list $(dropdown).find("option").remove(); <<<<<< Issue here // Fill drop down list with new data $(data).each(function () { // Create option var $option = $("<option />"); // Add value and text to option $option.attr("value", this.value).text(this.text); // Add option to drop down list $(dropdown).append($option); }); }); }
Then I can call the function as follows:
fillDropDown("/someurl/getdata", $("#dropdownbox1"))
Everything works fine except for one line where I clear old data from a drop down list. What am I doing wrong?
Any tips that might help improve this code are also greatly appreciated.
javascript jquery
Aetherix Mar 28 2018-12-12T00: 00Z
source share