get selected option internal text previously created by javascript

0

I am creating n amount of inputs Note credit, basically it is a div that contains a readonly input called Credit note, below a select with class "n_credito" and another input with class "amount".

I'm using an on change function to execute the following:

$(document).on('change','.n_credito', function () {
    //console.log($(this));
    var ncredit = $('select.n_credito option:selected').text();
    //console.log(ncredit_valor);
    //var ncredit_cor = ncredit_valor.split('e: ');
    //var ncredit = ncredit_cor['1'];
    console.log(ncredit);
    $(this).closest('div').find('.monto').val(ncredit);
    $(this).closest('div').find('.monto').attr("min","0");
    $(this).closest('div').find('.monto').attr("max",ncredit);
    ncredit = 0;
});

Basically puts the text of the selected value in the amount field. It happens that when there is only one created, it assigns the value perfectly. When there is more than one it seems that it concatenates the texts of the credit notes created. In the on change function I put the selected value in the n_credit variable. When there are two or more fields as in the image and I give the select by activating the onchange function, keep the following in n_credit

400-- Select credit note -

    
asked by Kinafune 02.09.2018 в 04:08
source

0 answers