Skip to content

Instantly share code, notes, and snippets.

@bruno-barros
Created October 29, 2012 12:34
Show Gist options
  • Save bruno-barros/3973274 to your computer and use it in GitHub Desktop.
Save bruno-barros/3973274 to your computer and use it in GitHub Desktop.
JS: popula cidades 'meucms'
/**
* POPULA COMBOBOX CIDADES
* @param UF : string do estado 'RJ'
* @param CIDID : ID da cidade
* @param obj_target : ID do select da cidade
* Ex: <input type="text" name="cep" id="cep" data-uf-id="uf" data-cidade-id="cidade" data-bairro-id="bairro" data-logradouro-id="logradouro" />
*/
function populaCidades(UF, CIDID, obj_target) {
myAj = $.ajax({
type: "POST",
url: V['site_url'] + "cms/cmsutils/comboCidade/" + UF,
dataType: ($.browser.msie) ? "text" : "html",
beforeSend: function() {
$('.loading-uf').show();
},
success: function(message) {
$('.loading-uf').hide();
if (message.length > 0){
$("#"+obj_target).html(message);
if(CIDID){
$("#"+obj_target).val(CIDID);
}
} else {
$("#"+obj_target).html('<option>Não existe</option>');
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment