Select populated via ajax when selecting value from another select by sending null to php

Asked

Viewed 333 times

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>
  • 1

    Try to remove the disabled before sending the data.

  • 1

    Replace disabled by readonly, you decided! Thank you very much!

  • 1

    Good, but just for information, readonly only works in input and textarea, 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, using bind in the submit, follows the link

1 answer

0


The solution was to remove the disabled before sending the data.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.