<script type="text/javascript">
setInterval(function() {
ObserveInputValue($('#cep').val());
}, 100);
function ObserveInputValue(valor){
var cep = valor.replace(/\D/g, '');
if (cep != "" && !document.getElementById('rua').value) {
var validacep = /^[0-9]{8}$/;
if(validacep.test(cep)) {
pesquisacep(cep);
}
}
}function limpa_formulário_cep() {
document.getElementById('rua').value=("");
document.getElementById('bairro').value=("");
document.getElementById('cidade').value=("");
}function meu_callback(conteudo) {
if (!("erro" in conteudo)) {
//Atualiza os campos com os valores.
document.getElementById('rua').value=(conteudo.logradouro);
document.getElementById('bairro').value=(conteudo.bairro);
document.getElementById('cidade').value=(conteudo.localidade);
} //end if.
else {
//CEP não Encontrado.
limpa_formulário_cep();
alert("CEP não encontrado.");
}
}
function pesquisacep(valor) {
//Preenche os campos com "..." enquanto consulta webservice.
document.getElementById('rua').value="...";
document.getElementById('bairro').value="...";
document.getElementById('cidade').value="...";
var script = document.createElement('script');
document.body.appendChild(script); };
</script>