?
Solved

onkeyup in javascript

Posted on 2009-02-24
2
Medium Priority
?
5,856 Views
Last Modified: 2012-05-06
The onkeyup event seems to have strange behavior where the keyCode field from the event object converts all keystrokes to uppercase.  This doesn't happen with onkeypress.  Is there some reason for this?

The code snippet below outputs "You pressed : S" when I enter a lowercase 's' into the text field.  But if I change the event to onkeypress, it outputs "You pressed : s"


<html>
<head>
<script type = "text/javascript">
function work(ev)
{
	var key = ev.keyCode || ev.which;
	var character = String.fromCharCode(key);
	alert("You pressed : " + character);
}
</script>
</head>
<body>
<input type="text" onkeyup="work(event)">
</body>
</html>

Open in new window

0
Comment
Question by:chsalvia
2 Comments
 
LVL 29

Expert Comment

by:Badotz
ID: 23724644
You might have to check for modifiers - shift, ctrl, alt - to correctly display the key value.
0
 
LVL 17

Accepted Solution

by:
contactkarthi earned 1000 total points
ID: 23725129
i am assuming that you want to convert the text to uppercase as you type.. if that is the case call a javascript function using onChange from the text box
function makeUppercase() {
document.form1.tbox.value = document.form1.tbox.value.toUpperCase();
}

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question