I dynamically make a -tag with JQuery. The options are made from a map I create with several ajax calls. When I visit the page the first time, it does have a select-tag but no options. However the second time I visit the page, the page has the options. So there is a delay, however when I put a console.log(map) in the function that creates the select-tag, it does display all the options.
Here is my code to create the select tags:
var namefield = $('<select></select>').attr("id","name");
getmapofpeoplefromindex(index); // this creates the map with 3 AJAX-calls
map.forEach(function(key,value){
namefield.append($("<option>").attr('value',value).text(key));
});
What is going wrong and how can I make sure I have a filled-in selectbox?