Page 1 of 1

text to other text field

Posted: Mon Nov 14, 2005 2:08 pm
by shiznatix
Original question:

what i want is what a user puts in text field A to go to text field B as soon as the user clicks away or if it was instant that would be cool too. what would be the JS for this?

Responce I got:

Well you can make it so that after so many characters it goes in there like so: (Lets say 8 chars for this example)

Code: Select all

<script type="text/javascript">
<!--
function switchFocus(num, fromNode, toEl)
{
    if (fromEl.value.length >= num) document.getElementById(toEl).focus();
}
// -->
</script>

A: <input type="text" id="A" name="A" onkeypress="switchFocus(8, this, 'B');" /> <input type="text" id="B" name="B" />
Or you can make it hop across when the user clicks away (although that sounds silly since they'd most likely either be "tabbing" to the other box or using the mouse but anyway:

Code: Select all

<script type="text/javascript">
<!--
function switchFocus(toEl)
{
   document.getElementById(toEl).focus();
}
// -->
</script>

A: <input type="text" id="A" name="A" onblur="switchFocus('B');" /> <input type="text" id="B" name="B" />
my new reply now
i don't want the cursor to go to the new text field, what i want is the text that was entered into the first text box to be coppied to the 2nd one onblur probably or if it could be done in real time that would be great. the 1st part is at the top of the page then i just want as they scroll down the text will have been copied into the textbox at the bottom.

Posted: Mon Nov 14, 2005 2:14 pm
by Burrito

Code: Select all

function copyIt()
{
   var field1 = document.getElementById('fieldone');
   var field2 = document.getElementbyId('fieldtwo');
   field2.value = field1.value;
}

<input type="text" name="fieldone" id="fieldone" onblur="copyIt()">
<input type="text" name="fieldtwo" id="fieldtwo">

Posted: Mon Nov 14, 2005 2:59 pm
by shiznatix

Code: Select all

function copyIt()
{
    document.getElementById('fieldone') = document.getElementbyId('fieldtwo');
}

<input type="text" name="fieldone" id="fieldone" onblur="copyIt()">
<input type="text" name="fieldtwo" id="fieldtwo">
worked perfect. thanks kiddies