I have a select that populates another select via ajax, all values are filled correctly, however 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 that fills 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 running ajax
<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>