0
I have the code below to load the cities:
$(function(){
$('#cod_estados').change(function(){
if( $(this).val() ) {
$('#cod_cidades').hide();
$('.carregando').show();
$.getJSON('cidades.ajax.php?search=',{cod_estados: $(this).val(), ajax: 'true'}, function(j){
var options = '<option value=""></option>';
for (var i = 0; i < j.length; i++) {
options += '<option value="' + j[i].cod_cidades + '">' + j[i].nome + '</option>';
}
$('#cod_cidades').html(options).show();
$('.carregando').hide();
});
} else {
$('#cod_cidades').html('<option value="">– Escolha um estado –</option>');
}
});
});
and the form:
<label for="cod_cidades">Cidade:</label>
<span class="carregando">Aguarde, carregando...</span>
<select name="cod_cidades" id="cod_cidades">
<option value="">-- Escolha um estado --</option>
</select>
it works perfectly only that I need to make a select that brings the options of the bank and if there is not the option desired by the person it can add, and when this happens I update only the select.
would be like having a button next to select for the user to add a new option to select and would be saved in the database?
– fernandoandrade
@fernandoandrade exactly this only that this code ai loads in the change event or it depends on the change of another combo and what I have to do it has to open normal and only stun if the user add something else in the bank.
– opeta
You can assemble this logo combo with php and make a function that reloads it in case the user adds new options, already leaving selected the new option.
– fernandoandrade