Copy value from one input to another

Asked

Viewed 2,986 times

2

I need that when I put any value inside input1, this value appears already in input2. Since you’re both on the same page, you can do this?

1 answer

3


Can do with jQuery capturing the event keyup.

Run the code below and see below an example working:

   
// JavaScript (usando jQuery).

$('#input1').keyup(function(){
    $('#input2').val($(this).val());
});
 <!-- HTML -->

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<input id="input1"/>
<input id="input2"/>

  • Thank you very much, this is exactly what I needed.

  • Suppose the field already has a value when we open the page, it has to copy the code at the moment when the page opens?

Browser other questions tagged

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