JSON LIST to SELECT dropdown
JSON LIST to SELECT dropdown
by graphettion
HTML
<select class="select-box"></select>
<button class="btn-go">Go</button>
JavaScript
var data = [{
"label": "Google",
"link": "https://google.com/"
}, {
"label": "Facebook",
"link": "https://facebook.com/"
}, {
"label": "Twitter",
"link": "https://twitter.com/"
}, {
"label": "LinkedIn",
"link": "https://linkedin.com/"
}];
var options = $.map(data, function(item, i) {
return $('<option>', {
text: item.label,
value: item.link
});
});
$(".select-box").empty().append(options);
$('.btn-go').on('click', function() {
window.open($('.select-box').val(), '_blank');
return false;
});