0
I’m using Viacep’s Webservice to do the street autocomplete on my registration form, but it’s a form where 20 lines, each line contains:
ZIP CODE + STREET OF THE CONDOMINIUM
when filling the zip code it has to complete the street only referring to that zip code of the same line, I tried using $("cep").next("rua").val(dados.lougradouro)
and I couldn’t.
//HTML
<table>
<tbody>
<tr>
<td><input type="text" name="cep_streetcond[]"></td>
<td><input type="text" name="street_streetcond[]"></td>
</tr>
<tr>
<td><input type="text" name="cep_streetcond[]"></td>
<td><input type="text" name="street_streetcond[]"></td>
</tr>
<tr>
<td><input type="text" name="cep_streetcond[]"></td>
<td><input type="text" name="street_streetcond[]"></td>
</tr>
<tr>
<td><input type="text" name="cep_streetcond[]"></td>
<td><input type="text" name="street_streetcond[]"></td>
</tr>
</tbody>
//JQUERY
$(document).ready(function() {
var cep_cond = $("input[name='cep_streetcond[]']");
var rua_cond = $("input[name='street_streetcond[]']");
cep_cond.blur(function() {
var cep_replace = $(this).val().replace(/\D/g, '');
rua_cond.val("Buscando...");
$.getJSON("https://viacep.com.br/ws/" + cep_replace + "/json/?callback=?", function(dados) {
if (!("erro" in dados)) {
$("input[name='cep_streetcond[]']").next().val(dados.logradouro);
} else {
alert("CEP não encontrado");
}
});
});
});
Thank you very much!
– F Silva