views:

100

answers:

3

All,

If suppose an entry is made First textbox can we retain the same entered text in 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.

+1  A: 
<html>
<script type="text/javascript">
function copy()
{
    var n1 = document.getElementById("n1");
    var n2 = document.getElementById("n2");
    n2.value = n1.value;
}
</script>
<label>First</label><input type="text" name="n1" id="n1">
<label>Second</label><input type="text" name="n2" id="n2"/>
<input type="button" value="copy" onClick="copy();" />
</html>
x2
+1  A: 

Well, you have two textboxes with the same ID. An Id should be unique, so you should prbably change this.

To set the value from one text box to another a simple call to getElementById() should suffice:

document.getElementById("n1").value=  document.getElementById("n2").value;

(assuming, of course you give your secodn text box an id of n2)

Tie this up to a button click to make it work.

James Wiseman
`.value` you meant to type there, right ?
Gaby
+2  A: 
<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"/>
Amarghosh
Thanks.........................
Hulk