Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, I have two input text boxe

Status
Not open for further replies.
Joined
Apr 27, 1999
Messages
705
Location
US

Hi,

I have two input text boxes, "txtA" and "txtB". What I would like to do is when the user is typing in "txtA", the text is also displayed in "txtB" simultaneously, preferably done in javascript. Does anyone have examples? Thanks.

fengshui_1998
 
answered in thread216-199682 --------------------------------------------------
Goals are dreams with deadlines
 
This works (sort of)...

Type in text in the top textbox, then click on lower textbox. The text from the upper one will appear in the lower. Im sure there's a way to do this without clicking on the lower box.

It's probably explained in the thread mentioned above.

Good Luck!

<html>

<head>

<title>Writing to text box</title>

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>



function subWrite() {



var newContent = document.forms[0].entry.value

document.forms[1].entry.value=newContent



}

</script>

</head>

<body>

<form>

<input type=&quot;text&quot; NAME=&quot;entry&quot; VALUE=&quot;&quot; onChange=&quot;subWrite()&quot;>

</form>
<form>

<input type=&quot;text&quot; NAME=&quot;entry&quot; Value=&quot;&quot;>

</form>

</body>

</html>
 
I don't know if you got this or not but this will work.

<head>
<script language=javascript>
function doCopy(){
formName.text2.value=formName.text1.value;
}
</script>
</head>
<body>
<form name=formName id=formName>
<input type=text name=text1 id=text1 onKeyup=&quot;doCopy()&quot;>
<input type=text name=text2 id=text2>
</form>
</body>

Roj
 
I did not really explained anything in that thread - I just wrote an example script, but the key is to use onKeyUp event handler.
onChange only fires when the box losees the focus (you click on boxB or anywhere else on the page), but onKeyUp will fire after a single letter is typed (you press the button on the keyboard and as you release it - the even is fired).
as a side note to your script (I hope you do not mind) - you should not give the same name to 2 different elements --------------------------------------------------
Goals are dreams with deadlines
 
I did not really explaine anything in that thread - I just wrote an example script, but the key is to use onKeyUp event handler.
onChange only fires when the box loses the focus (you click on boxB or anywhere else on the page), but onKeyUp will fire after a single letter is typed (you press the button on the keyboard and as you release it - the even is fired).
as a side note to your script (I hope you do not mind) - you should not give the same name to 2 different elements --------------------------------------------------
Goals are dreams with deadlines
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top