Pass array to modal with JQUERY

Asked

Viewed 21 times

-1

Talk personal, all right? I have a little problem here that is taking my sleep. rs I can pass variables to the modal quietly as in the example below:

Button that switches the variable to the modal:

<button class="btn btn-primary btn-xs tooltips" data-placement="top" data-original-title="AlterarBoletos"
data-toggle="modal" 
data-target="#alterarboletoscheckbox" 
data-alt_ndoc="<?php echo $variavel ?>"
><i class="fas fa-magic"></i>
</button> 

The problem ta when I need to pass information to the array:

<input type="checkbox" name="excluir[]" id="excluir[]" value="<?php $variavel ?>" /> 

<button class="btn btn-primary btn-xs tooltips" data-placement="top"            data-original-title="Alterar Boletos" 
                                                    data-ndoc_checks="<?php echo $this->input->post('excluir') ?>"
                                                    data-toggle="modal" 
                                                    data-target="#alterarboletoscheckbox" 
                                                    data-alt_ndoc="excluir[]"
                                                    ><i class="fas fa-magic"></i>
                                                </button> 

JQUERY:

$('#alterarboletoscheckbox').on('show.bs.modal', function (event) {
    var button = $(event.relatedTarget) // Button that triggered the modal
    var alt_ndoc = button.data('alt_ndoc') // Extract info from data-* attributes

    var modal = $(this)
    
    modal.find('#alt_ndoc').val(alt_ndoc)
    
})

My result is simply ' delete[] '. Someone give me a light? Thank you very much!

1 answer

0

Talk people. I got it here! Can close! :)

$('#alterarboletoscheckbox').on('show.bs.modal', function (event) {
    var idBoletos = "";
    var qtdBoletos = "";

    $.each($("input[name='excluir']:checked"), function(){
        //PEGANDO O VALOR E COLANDO UMA VIRGULA
        idBoletos += $(this).val()+",";
        qtdBoletos = $('input[type=checkbox]:checked').length;
    })
    var button = $(event.relatedTarget) 
    var nomecorretor = button.data('nomecorretor')
    nomecorretor = nomecorretor.substring(0, nomecorretor.indexOf(" ")).toUpperCase();
    var modal = $(this)

    modal.find('#idBoletos').val(idBoletos)
    $(".textoQtd span").text(nomecorretor + ", você está alterando " +qtdBoletos + " boleto(s).")
    
})

Browser other questions tagged

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