0
Good afternoon!
HTML
<label class="labelPequeno">Cidade</label>
<select class="typeTextMedio" name="cidade" id="cidade" required>
<option value="" selected>Selecione a cidade</option>
</select>
Javascript
option = document.createElement( "option" );
option.value = "28510";
option.text = "Muriaé";
option.selected;
$("#cidade").add( option );
The idea is to create a option
in the select
with id="cidade"
, but it is not adding.
What is wrong?
I tried that too but it didn’t work:
$('#cidade').append($("<option></option>")
.attr("value","<?php echo $cidade["id"]; ?>")
.text("<?php echo $cidade["nome"]; ?>")
.attr("seleted","selected");
Also so:
$("#cidade").append('<option value="<?php echo $cidade["id"]; ?>"><?php echo $cidade["nome"]; ?></option>');
Didn’t work!
Use
append
instead ofadd
.– Pedro Camara Junior
take a look at the end of the question
– Carlos Rocha
https://jsfiddle.net/PetrusStarken/33rpxLf9/1/
– Pedro Camara Junior