1
I have a select that fills another select via ajax, all values are filled correctly, but when saving, it sends null.
First select:
<select name="clientesel" class="form-control js-example-basic-multiple" id="clientesel" >
<option value="">Selecione</option>
<?php foreach ($clientes as $cliente) { ?>
<option value="<?php echo $cliente['Cliente']['cli_codigo_id']; ?>"><?php echo $cliente['Cliente']['cli_codigo_id'] . " - " . $cliente['Pessoas']['pes_razao_nome']; ?></option>
<?php } ?>
</select>
Second select
<select name="pagamento" class="form-control" id="pagamento">
<option value="">Selecione</option>
<?php foreach ($form_pagto as $pgto) { ?>
<option value="<?php echo $pgto['FormaPagamento']['frec_codigo_id']; ?>"><?php echo $pgto['FormaPagamento']['frec_descricao']; ?></option>
<?php } ?>
</select>
JS filling the second from the first
$('#pagamento').val(data.Cliente.cli_forma_recebimento);
$("#pagamento option").each(function() {
if($(this).val() == data.Cliente.cli_forma_recebimento) {
$(this).attr("selected", true);
}
});
HTML after ajax execution
<select name="pagamento" class="form-control" id="pagamento" disabled="true">
<option value="">Selecione</option>
<option value="01" selected="selected">CHEQUE</option>
<option value="02">BOLETO</option>
<option value="03">DEPÓSITO</option>
<option value="05">VALE</option>
<option value="06">TRANSFERÊNCIA</option>
<option value="07">SOMENTE DINHEIRO</option>
<option value="08">SEM FATURA</option>
<option value="09">CARTÃO DE DÉBITO</option>
<option value="10">CARTÃO DE CRÉDITO</option>
</select>
Try to remove the
disabled
before sending the data.– Augusto
Replace disabled by readonly, you decided! Thank you very much!
– Lucas Thibau Paulino
Good, but just for information,
readonly
only works ininput
andtextarea
, then it will still be possible to change the value of select. If it is important that the user cannot change the value I suggest you do as in the example, usingbind
in thesubmit
, follows the link– Augusto