1
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 Estaticas combobox, for dynamic combobox it does not work. I’m already hours researching and I can’t 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>
<div class="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 the courses that are in the database and fills the select, dynamically, it turns out that whenever I send the form I wanted it to mark up the selected option..
What did you try? Add the code to the question.
– Vinícius Gobbo A. de Oliveira
And the code that generates the
data
for its functionJavaScript
? That’s where you need to check whichoption
ofselect
was sent and return.– user3603