![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Oct 2005
Location: Texas
Posts: 11
Rep Power: 0
![]() |
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> |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
|
try onKeyUp
|
|
|
|
|
|
#3 |
|
Professional Programmer
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 484
Rep Power: 4
![]() |
onKeyDown should work fine also
|
|
|
|
|
|
#4 |
|
Newbie
Join Date: Oct 2005
Location: Texas
Posts: 11
Rep Power: 0
![]() |
Thank you very much for your help. It works now.
![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|