Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Tagged as

Recent value with KeyPress

, 3 Oct 2011
Rate this:
Please Sign up or sign in to vote.
Why don't you try for the onkeyup event. You don't even need to read the last character and concatenate it. Keypress event is a combination of keydown and keyup event. Below is the sample code to test the response when the keypress and keyup event occurs.Test KeyPress event: <input...
Why don't you try for the onkeyup event. You don't even need to read the last character and concatenate it.
 
Keypress event is a combination of keydown and keyup event. Below is the sample code to test the response when the keypress and keyup event occurs.
 
Test KeyPress event: 
 
<input type="text" id="fname1" onkeypress="upperCase(this.id)" />
 
Test KeyUp Event: 
 
<input type="text" id="fname2" onkeyup="upperCase(this.id)" />
 

<script type="text/javascript">
function upperCase(x)
{
var y=document.getElementById(x).value;
document.getElementById(x).value=y.toUpperCase();
}
</script>
 
During the test run, you will notice that the last character does not convert to its uppercase during the keypress event, but it gets converted during the keyup event.
 
Also, the keypress event does not allow you to handle the control keys like - SHIFT, ALTER, CONTROL, while the keyup and keydown events allow you to handle these keys.
 
Hope I have made my point clear to you.
 
Thanks & regards,
Niral Soni

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Niral Soni
Business Analyst Tata Consultancy Services Ltd.
India India
I started my career as Java Developer. But now more inclined towards web designing, JavaScript, HTML and CSS.I have good level of expertise on Java, Oracle and JavaScript. Designing Generic components is my main expertise.
Follow on   Twitter   Google+

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 3 Oct 2011
Article Copyright 2011 by Niral Soni
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid