Send data from one modal to another modal

Asked

Viewed 245 times

2

I have a modal call details, I have the following data on it:

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

That were 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 input data (id and name) of modal details for the modal alert?

1 answer

1


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

Put a class on 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 modal alert, put that:

<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 will run the function called by class button that will take the value of fields texts and put in fields hiddens within the modal.

  • 1

    You’re the Fastest men Alive.

Browser other questions tagged

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