Send data from one modal to another modal

2

I have a modal called details , I have the following data in it:

<input type="text" class="form-control" id="id" name="id" required>  
<input type="text" class="form-control" id="nome" name="nome" required>               

That was filled in like this:

modal.find('.modal-body input[name="id"]').val(id)
modal.find('.modal-body input[name="nome"]').val(nome)

When I call the second modal alert by the button:

<button type="submit" data-toggle="modal" data-target="#alterar">Salvar</button>      

How to pass the input's data (id and name) of modal details to the modal alert ?

    
asked by anonymous 14.12.2015 / 19:22

1 answer

1
<button type="submit" data-toggle="modal" data-target="#alterar" class="modalAlerta">Salvar</button>

Put a class in button , in which case I called modalAlerta . Create a function like this:

$('.modalAlerta').on('click', function(){
    var nome = $("#nome").val();
    var id   = $("#id").val();

    $('#nome-hidden').val(nome);
    $('#id-hidden').val(id);
});

Within the alert modal, put this:

<input type="hidden" class="form-control" id="id-hidden" name="id-hidden">  
<input type="hidden" class="form-control" id="nome-hidden" name="nome-hidden">

When you click to open the modal it will run the function called by the class of the button that will take the value of the fields texts and put it in fields hiddens within modal.     

14.12.2015 / 19:27