1
called js.
function clienteChange() {
var id = $('#idCliente').val();
$.ajax({
url:"/Entregas/clientes.endereco.php?id=" + id,
dataType : 'json',
success:function(result) {
$('[name="cham_endereco[]"]').val(result.endereco);
$('[name="cham_numero[]"]').val(result.numero);
$('[name="cham_bairro[]"]').val(result.bairro);
$('[name="cham_cidade[]"]').val(result.cidade);
}
});
}
To fetch the results, I made the.endereco.php clients this way:
$result['endereco'] = "teste";
die(json_enconde($result));
called Add.php
<tbody id="servicosTable" style="width: 898px;">
<tr id="servico_0">
<td style="line-height: 10px !important;">
<select class="input-small" name="cham_tiposervico[]">
<option value="0" selected >Coleta</option>
<option value="1" >Entrega</option>
<option value="2" >Retorno</option>
</select>
</td>
<td style="line-height: 10px !important; font-size: 12px !important;">
<input class="input-small" style="width: 222px !important;" type="text" name="cham_endereco[]" value="">
</td>
<td style="line-height: 10px !important; font-size: 12px !important;">
<input class="input-small" style="width: 50px !important;" type="text" name="cham_numero[]" value="">
</td>
<td style="line-height: 10px !important; font-size: 12px !important;">
<select class="input-small selectCidade" name="cham_cidade[]" id="cham_cidade[]" style="width: 140px;">
<option value="0">Selecione</option>
<? foreach($this->data['listaCidade'] as $cidade){ ?>
<option value="<? echo $cidade->idCidade; ?>"><? echo $cidade->cidade; ?></option>
<? } ?>
</select>
</td>
<td style="line-height: 15px !important; font-size: 12px !important;"> <select class="input-small selectBairro" name="cham_bairro[]" id="cham_bairro[]" style="width: 120px;">
<option value="">Selecione</option>
</select>
</td>
<td style="line-height: 15px !important; font-size: 12px !important;">
<input class="input-small" type="text" name="cham_falarcom[]" value="">
</td>
<td>
<button class="btn" type="button" onclick="removerServico(0)" style="padding: 3px; width: 32px !important;"><i class="icon-trash"></i></button>
</td>
</tr>
</tbody>
This is the select that searches the customers... and when selecting, you must print the address of each in their respective fields, address, number, neighborhood and city.
Form:
select class="input-xxlarge" style="width: 409px !important;" id="idCliente" name="idCliente" onchange="clienteChange()"
But I’m not quite sure what would be wrong?
Then, about the field name has to be with [] because it is an array, where we will post several fields with the same name, and can add with one button or remove with another. Otherwise, I’ll do the tests to see, it’s an interesting idea... Thank you.
– Sr. André Baill
Opa @Andrébaill, yes! If this is the intention, sorry for the intrusion then hehe. But the problem is in the return. By POSTMAN you can see the document type (needs to come as JSON). If you are online, there are tools like http://www.webconfs.com/http-header-check.php for viewing the header
– Felipe Douradinho
Don’t forget to vote on my answer if you succeed hehe.
– Felipe Douradinho
Okay Felipe, thanks for your help. I’ll run the tests. Skype me? Hug!
– Sr. André Baill
Put man, I don’t use =/
– Felipe Douradinho