$(document).on('change', '#selectfolders', function(e) { //getFolders(this.options[e.target.selectedIndex].text); show }); function getAllFolders(){ //Get DB 2 HTML //has to be synchronus in order to update before loading the rest $('#selectfolders').find('option').remove() $.ajax({ type: "GET", url: "getconfigs", async: false, dataType: "json", success: function(data) { $.each( data, function( key, value ) { $('#selectfolders').append("") }); } }); } $(document).ready(function() { getAllFolders(); });