jQuery plugin question - populate select options with JSON data
Posted
by user331884
on Stack Overflow
See other posts from Stack Overflow
or by user331884
Published on 2010-05-13T23:47:09Z
Indexed on
2010/05/13
23:54 UTC
Read the original article
Hit count: 281
I'm trying to fill selects with json data from a web service. I'm getting error 'Object doesn't support this property or method.' when I do this $(this).html(options.join'')); Any ideas what I'm doing wrong?
;(function($) {
$.fillSelect = {};
$.fn.fillSelect = function(url, map) {
var jsonpUrl = url + "?callback=?";
$.getJSON(jsonpUrl,
function(d) {
var options = [];
var txt = map[0];
var val = map[1];
options.push('<option>--Select--</option>');
$.each(d, function(index, item) {
options.push('<option value="' + item[val] + '">' + item[txt] + '</option>');
});
$(this).html(options.join('')); //getting error Object doesn't support this property or method
}
};
})(jQuery);
© Stack Overflow or respective owner