This discussion is archived
3 Replies Latest reply: Jul 18, 2013 4:38 AM by mrosa001 RSS

setting item value from javascript

mrosa001 Newbie
Currently Being Moderated

Hi,

 

I have a url  ( .js ) and filled itens in my application,

the url is : http://cep.correiocontrol.com.br/"+cep1+".js

 

where cep1 is a item where I will type the number , like 13280000

 

I got this javascript in the web :

 

<script type="text/javascript">

function atualizacep(cep1){

cep1 = cep1.replace(/\D/g,"")

url="http://cep.correiocontrol.com.br/"+cep1+".js"

s=document.createElement('script')

s.setAttribute('charset','utf-8')

s.src=url

document.querySelector('head').appendChild(s)

}

 

 

function correiocontrolcep(valor){

if (valor.erro) {

alert('Cep não encontrado');

return;

};

document.getElementById('logradouro').value=valor.logradouro

document.getElementById('bairro').value=valor.bairro

document.getElementById('localidade').value=valor.localidade

document.getElementById('uf').value=valor.uf

}

</script>

I am calling the javascript like this :

 

onChange="javascript:atualizacep('CEP1')";

 

but the itens

LOGRADOURO

BAIRRO

LOCALIDADE

UF still empty.

 

I appriciate any help with javascript and this way to call.

 

thank you.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points