JQuery:
$(function() {
$(document).delegate('#estado', 'change', function() {
var valor = $('#estado').val();
$('#cidade').load('_requires/cidades.php?estado=' + valor );
});
$(document).delegate('#cidade', 'change', function() {
var valor = $('#cidade').val();
alert(valor);
$('#bairro').load('_requires/bairros.php?cidade=' + valor );
});
});
HTML:
<div>
<label class="labelPequena">Estado</label><br />
<select class="typeTextMedio" id="estado" name="estado" required>
<option value="">Escolha o Estado</option>
<option value="MG">MG</option>
<option value="ES">ES</option>
<option value="RJ">RJ</option>
<option value="SP">SP</option>
</select>
</div>
<div>
<label class="labelPequena">Cidade</label><br />
<select class="typeTextMedio" id="cidade" name="cidade" required>
<option value="">Escolha a Cidade</option>
</select>
</div>
<div>
<label class="labelPequena">Bairro</label><br />
<select class="typeTextMedio" id="bairro" name="bairro" required>
<option value="#">Indiferente</option>
</select>
</div>
When you select in combo estados
, popular combo cidades
. This is working.
When you select in combo cidades
, popular combo bairro
. This is NOT working. But I noticed that in% w / w% only ERR occurs with the first city only, and when I click on it, the event does not occur. With the others it usually occurs.
An important observation is that if you choose second city of combo cidades
, and combo
of neighborhoods are loaded, then go back and select the first city again, so now it works. On the first try neither combo
works!
How to solve?