apopular Posted March 27, 2015 Share Posted March 27, 2015 Hi, i´m trying to add postcode find address, suburb and state, you can test in this address: http://apopular.com.br/aacep.html (Try 12210-250 , 11080-300 , 01001-001 ) The code is very simple: CEP: <input type="text" id="cep" maxlength="9" placeholder="Ex: 13483-087"/><br/> Endereço: <input type="text" id="endereco"/><br/> Bairro: <input type="text" id="bairro"/><br/> Cidade: <input type="text" id="cidade"/><br/> UF: <input type="text" id="uf"/> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script> // Registra o evento blur do campo "cep", ou seja, quando o usuário sair do campo "cep" faremos a consulta dos dados $("#cep").blur(function(){ // Para fazer a consulta, removemos tudo o que não é número do valor informado pelo usuário var cep = this.value.replace(/[^0-9]/, ""); // Validação do CEP; caso o CEP não possua 8 números, então cancela a consulta if(cep.length!=8){ return false; } // Utilizamos o webservice "viacep.com.br" para buscar as informações do CEP fornecido pelo usuário. // A url consiste no endereço do webservice ("http://viacep.com.br/ws/"), mais o cep que o usuário // informou e também o tipo de retorno que desejamos, podendo ser "xml", "piped", "querty" ou o que // iremos utilizar, que é "json" var url = "http://viacep.com.br/ws/"+cep+"/json/"; // Aqui fazemos uma requisição ajax ao webservice, tratando o retorno com try/catch para que caso ocorra algum // erro (o cep pode não existir, por exemplo) o usuário não seja afetado, assim ele pode continuar preenchendo os campos $.getJSON(url, function(dadosRetorno){ try{ // Insere os dados em cada campo $("#endereco").val(dadosRetorno.logradouro); $("#bairro").val(dadosRetorno.bairro); $("#cidade").val(dadosRetorno.localidade); $("#uf").val(dadosRetorno.uf); }catch(ex){} }); }); </script> I DONT KNOW WHY, 8) when i upload this in another oscommerce file does not work, try again... https://www.apopular.com.br/corporativo.php (After footer for example) Anybody know why oscommerce does´t read this js code? i test in many pages, create_account, contact_us, Thanks to help. Marcelo I did, helped or traslate. http://addons.oscommerce.com/profile/104964 My english it´s só poor, but of you need help in portuguese, like shipping and payment that´s make a diference in brazil, come one, Obrigado (thank´s) Link to comment Share on other sites More sharing options...
Bob Terveuren Posted March 28, 2015 Share Posted March 28, 2015 Hi There's two calls to the code <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> in the page at https://www.apopular.com.br/corporativo.php- that has a habit of breaking jQuery - if you run the page in a browser with Dev Tools you'll get a message TypeError: $(...).mask is not a function try taking out the above line on your page at the footer and see what happens. Likewise on an osCommerce 2.3.x store there will already be a call to jQuery and if you repeat that it breaks stuff Link to comment Share on other sites More sharing options...
apopular Posted March 28, 2015 Author Share Posted March 28, 2015 @@Bob Terveuren Tank you very much, problem solved, Have a nice weekend, Marcelo I did, helped or traslate. http://addons.oscommerce.com/profile/104964 My english it´s só poor, but of you need help in portuguese, like shipping and payment that´s make a diference in brazil, come one, Obrigado (thank´s) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.