My jquery/javascript problem: I need to return the code of an html select input, but I also need to set the selected option dynamically.
function(data){
return '<select class="form-control"'+
'<option value="1"'+ if(data === 1){selected}+'>Name 1</option>'+
'<option value="2"'+ if(data === 2){selected}+'>Name 2</option>'+
'<option value="3">Name 3</option>'+
'</select>';
}
Attention: using $(selector).val(data); AFTER the html is rendered is NOT an option (unfortunately)