function teste(){ console.log("asdasdas") }
function buscaCep(){ let cep = document.getElementById('form-field-cep').value; if(cep !== ""){ let url = "https://brasilapi.com.br/api/cep/v1/" + cep; let request = new XMLHttpRequest(); request.open("GET", url); request.send(); request.onload = function(){ if(request.status === 200){ let endereco = JSON.parse(request.response); document.getElementById("form-field-rua").value = endereco.street; document.getElementById('form-field-bairro').value = endereco.neighborhood; document.getElementById('form-field-cidade').value = endereco.city; document.getElementById('form-field-estado').value = endereco.state; } else if(request.status === 404){ alert("CEP inválido!") } else{ alert("Erro ao fazer a requisição"); } } } } window.onload = function(){ let campoCep = document.getElementById("form-field-cep"); campoCep.addEventListener("blur", buscaCep); }

Sign Up

Login