I have a button event that triggers an ajax that loads the data as an example.
$('#table_com_parcelas tbody').append('<tr><td class="align">' + x + ' de ' + parcelas + '</td><td class="align">' + vencimento + '</td><td class="align">R$ ' + mascaraValor(valor.toFixed(2)) + '</td><td class="align"><select id="select-' + x + '" onchange="('+this.id+')>"' + insere_option() + '</select></td></tr>');
Ajax loads from 1 to 12 selects, it depends on the number of parcels chosen, however the event onchange="('+this.id+')"
carries the button id and not the select in question.
Is there any way to enter onchange()
after all the selects have been filled in? or have another way to select the select that was clicked
below functions used;
while (x <= parcelas) {
data_sun += 30;
var vencimento = adicionarDiasData(data_sun, data);
var valor = total / parcelas;
$('#table_com_parcelas tbody').append('<tr><td class="align">' + x + ' de ' + parcelas + '</td><td class="align">' + vencimento + '</td><td class="align">R$ ' + mascaraValor(valor.toFixed(2)) + '</td><td class="align"><select id="select-' + x + '">' + insere_option() + '</select></td></tr>');
x++;
}//carrega os selects
type_of_payment();//chama a função que seta os outros selects. Aqui o onchange está funcionando.
Carraga options;
function insere_option() {
var options = "";
options += "<option value=''>Selecione</option>";
options += "<option value='1'>Boleto</option>";
options += "<option value='2'>Cartão</option>";
options += "<option value='3'>Cheque</option>";
options += "<option value='4'>Dinheiro</option>";
options += "<option value='5'>Transferência</option>";
return options;
}
Since all are nested I have another function that arrows the subsequent options with the same item selected.
function type_of_payment() {
var selects = $("#table_com_parcelas select");
var index = null;
var valor = null;
selects.on('change', function () {
var valor = this.value;
indice = selects.index(this);
selects.each(function (index) {
if (index > indice) {
$(this).val(valor);
}
});
});
}