0
I’m populating a SELECT
from a JSON
received via AJAX
as follows:
$.each(parsedData, function(i, produto) {
$('select#produtos').append(
$('<option></option>').val(produto.cod_produto).html(produto.descricao)
);
});
I’m trying to assign the SELECTED
in those options
, but without success. Using:
$('<option></option>').val(produto.cod_produto).html(produto.descricao).attr('selected', true)
Or even with .attr('selected','selected')
and I get the error:
Uncaught Syntaxerror: Missing ) after argument list
Continuing the attempts:
.prop("selected", "selected")
Uncaught Typeerror: $(...). val(...). html(...). prop is not a Function
Do you want to Selected only from the first item? ever tried to make a callback?
– Gabriel Rodrigues
Whether to select in a
option
with a specific value?– Miguel
@Gabrielrodrigues I will assign to a specific value, I have not tried callback.
– Marcelo de Andrade
Yes, @Miguel. Exactly.
– Marcelo de Andrade