JavaScript: Convert characters to uppercase when typing

Filed in: Web Development — April 7th, 2004

In some web form fields, we required user to fill in data in uppercase. We can do this by appyling a javascript function.

Code:
<script>
function uppercase()
{
key = window.event.keyCode;
if ((key > 0x60) && (key < 0x7B))
window.event.keyCode = key-0x20;
}
</script>

Then, add onKeypress="uppercase();" in the field that you want to have uppercase strings. Done!

Source: Making HTML as Functional as a Green Screen

Like this post? Please share:

Follow @liewcf on Twitter; Join Facebook page; Subscribe to free newsletter for updates like this article..

  • http://www.ibnjuferi.com/ MENJ

    Very interesting, lcf… :D BTW, can link to my blog-ah? *wink* *wink*

    - MENJ

  • http://www.menj.org/weblog menj

    Very interesting, lcf… :D BTW, can link to my blog-ah? *wink* *wink*

    - MENJ

t