Get input text values inside modal-body

Asked

Viewed 913 times

0

Expensive;

How to get INPUT TEXT values and direct them to Body-Modal?

I have a form with several inputs disabled, so that the user does not edit. However, when clicking the button that calls the Modal, I wanted the values of this INPUT to appear in the modal.

MODAL:

inserir a descrição da imagem aqui

FORM:

inserir a descrição da imagem aqui

Sorry for posting the image, I tried to put the code and it was not going to be formatted. I count on your help.

Grateful.

  • To add formatted code just paste the code, select it completely, and click the button { } above the text editor, or add four spaces before you start writing code.

2 answers

1

Expensive;

I solved my problem with the code below:

function copy_form()
{
id('modalxxx').value = id('xxx').value;
id('modalyyy').value = id('yyy').value;
id('modalrrr').value = id('rrr').value;
id('modalttt').value = id('ttt').value;


}

function id( el ){
   return document.getElementById( el );
}
    window.onload = function()
    {
    id('btnenviar').onclick = function()
    }
    copy_form();
}
                 }

</script> 

Thanks for your help :)

0

First thing: The answer I’m going to give you is using jQuery.

To access the value of an input field using jQuery, make sure you set an id for each of them. Then, inside your javascript code, access the value as follows:

var input_value = $("seu_id").val();

To add these values in the form, the ideal is that you, by clicking "Click Here", recover all the values of the Fields input, and seven these values in the Fields of your form. To do this, you must define text blocks in your modal, each with an id. Assuming you have an input field with your name, and you want to send it to modal. Assuming your modal has a paragraphe as follows:

<p id="nome_modal"></p>

And that in your form you have an input field defined as follows:

<input type="text" id="nome disabled />

Using jQuery, you will:

var nome = $("nome").val();
$("#nome_modal").text(nome);

Browser other questions tagged

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