Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 24th, 2005, 6:13 PM   #1
rag05
Newbie
 
rag05's Avatar
 
Join Date: Oct 2005
Location: Texas
Posts: 11
Rep Power: 0 rag05 is on a distinguished road
Help with onKeyPress

Hello all,

Let's say I want to copy the value of one text box into another as the user is typing the information. I was trying to do this using onKeyPress, but it is always one key stroke behind the user.

Let's say for example, the user enters '4' (textbox1)... textbox2 doesn't display anything.

Then, if the user enters a second number so we have '49', textbox2 will only display '4'. When the user has entered '495', textbox2 only displays '49'... and so forth.

Is there anything I can do so textbox2 shows the current value immediately?

I'm fairly new to JavaScript, so I appreciate your help. Here's a sample of the code I'm using:

<script language=javascript>
	function copyText(val)
	{
		document.testform1.text2.value = val.value;
	}
</script>
<HTML>
<HEAD></HEAD>
<BODY>
<form name=testform1>
<INPUT type="text" id=text1 name=text1 onKeyPress="copyText(this)">
<br><p>
<INPUT type="text" id=text2 name=text2>
</form>
</BODY>
</HTML>
rag05 is offline   Reply With Quote
Old Oct 25th, 2005, 2:05 AM   #2
bja888
Hobbyist Programmer
 
bja888's Avatar
 
Join Date: Oct 2005
Location: Central, FL
Posts: 213
Rep Power: 0 bja888 is an unknown quantity at this point
Send a message via AIM to bja888 Send a message via Yahoo to bja888
try onKeyUp
bja888 is offline   Reply With Quote
Old Oct 25th, 2005, 4:31 AM   #3
ivan
Professional Programmer
 
ivan's Avatar
 
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 484
Rep Power: 4 ivan is on a distinguished road
onKeyDown should work fine also
ivan is offline   Reply With Quote
Old Oct 25th, 2005, 9:26 AM   #4
rag05
Newbie
 
rag05's Avatar
 
Join Date: Oct 2005
Location: Texas
Posts: 11
Rep Power: 0 rag05 is on a distinguished road
Thank you very much for your help. It works now.
rag05 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:37 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC