I need to keep the option chosen in the combobox after the page is submitted, I have a function that does this, but only for combobox static, for the dynamic combobox it does not work. I'm already searching for hours and can not find anything.
function cursos() {
$.getJSON('https://localhost/uan/curso/pesquisaPor/', {}).done(function(data) {
$.each(data, function(id, valor) {
$("#curso").append('<option value="' + valor.id + '">' + valor.nome + '</option>');
});
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divclass="control-group">
<label class="control-label">Curso<span class="required">*</span>
</label>
<div class="controls">
<select class="span6 m-wrap" id="curso" name="curso">
<option value="">Selecciona um curso</option>
</select>
</div>
</div>
The courses function returns all courses that are in the database and populates the select dynamically, it happens that whenever I submit the form I wanted it to mark up the selected option ..