get modal window textbox in a new one

1

Does anyone know how to get the value of a text box from a modal window in another new modal window?

I have a modal window that has two buttons, I also have a key value in a textbox that I need to recover in another modal window to process that value, I tried to pass the value in the click event of a button with the following code

$("#btnno").click(function () {
  $('#modalPregunta').modal('hide');
  $('#modalNo').modal('show',$("#valor").val());
});

and I got it back like that

$('#modal').on('show.bs.modal', function (evnt) {

  var btn = $(evnt.relatedTarget);  
  console.log( btn);
});

but debugging it does not get me any value

    
asked by Drago25 23.02.2016 в 22:21
source

2 answers

1

You can effectively get the value of the first modal window using JQuery or JavaScript. With JQuery we use $('#elementoID').val(); this gets the value of the element with the ID "elementID", since the modal windows do not lose their values when closing the value will still be present in the element even if it is hidden, another alternative may be to store the value that you need the first modal window in a global variable, if it is required and later in your code you only use the value of that variable.

    
answered by 23.02.2016 / 23:53
source
1

The solution to the problem was to recover the value only with $ ("# value"). val () which is the textbox of my first modal window, without passing any value in the click event $ ('# modalNo'). modal ('show', $ ("# value"). val ());

    
answered by 23.02.2016 в 23:05