Hulk Hulk - 4 months ago 7
HTML Question

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>


Thanks.

Answer
<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"/>