Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy contents of one textbox to another

Suppose an entry is made in a textbox. Is it possible to retain the same entered text in a second text box? If so, how is this done?

<html>
      <label>First</label>
      <input type="text" name="n1" id="n1">
      <label>Second</label>
      <input type="text" name="n1" id="n1"/>
</html>
like image 655
Hulk Avatar asked Feb 18 '10 08:02

Hulk


People also ask

How do you get the value of a textbox from one textbox to another?

All one need to do is to bind keyup event on textbox and then copy textbox value to another textbox. Below jQuery code will copy text from txtFirst and copy it to txtSecond. $(document). ready(function() { $('#txtFirst').

How can copy textbox value from another in Javascript using checkbox?

You can write a javascript function to copy value from one textbox into the other textbox, and call the same function on “onclick” event of the checkbox. Same function can be used to clear the textbox on unchecking the checkbox.


1 Answers

<script>
function sync()
{
  var n1 = document.getElementById('n1');
  var n2 = document.getElementById('n2');
  n2.value = n1.value;
}
</script>
<input type="text" name="n1" id="n1" onkeyup="sync()">
<input type="text" name="n2" id="n2"/>
like image 113
Amarghosh Avatar answered Oct 09 '22 23:10

Amarghosh