Skip to content

Commit

Permalink
Update index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeHELPNET authored Mar 2, 2023
1 parent b51b172 commit bd9752a
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,33 @@ <h1>Consulte o CEP</h1><br>

</div>

<script src="src/js/main.js"></script>
<script>

const cep = document.querySelector('#cep')

const showData = (result) => {
for(const campo in result){
if(document.querySelector('#'+campo)){
document.querySelector('#'+campo).value = result[campo]
}
}
}

cep.addEventListener('blur', (e)=>{
let search = cep.value.replace('-','')
const options = {
method: 'GET',
mode: 'cors',
cache: 'default'
}
fetch(`https://viacep.com.br/ws/${search}/json/`, options)
.then(response=>{response.json()
.then(data => showData(data))
})
.catch(e => console.log('Deu Erro: '+ e,message))

})
</script>

</body>
</html>

0 comments on commit bd9752a

Please sign in to comment.