- Posted by: Paresh Rawal
- Posted on: September 09 2003 09:56 EDT
I have a unique problem.. I need to convert data entered in a text box to be displayed in CAPS. This has to be done real time... I mean, if a user enters a text - my test message, the string has to be converted into MY TEST MESSAGE and this has to be done after the user enters each character(alphabet).
If anybody has any idea, pls do let me know..
Thanks in advance,
onkeyup="this.value = this.value.toUpperCase()"></textarea>
No the "onkeyup" event handler is relative recent, so there are no guarantees that this will work on older browsers. I think it will work on Mozilla, Netscape 6+ and IE 4+.
Hi Paul !
Thanks for the reply but I did try this solution. When I try to edit the entered data, the cursor is forced back to the end of the string.
example, if I enter abcdeg and try to go back by hitting the left key to enter f before the g, then the cursor is forced back the end of the string.
I am using IE 5.5.
I suggest you use the onchange event instead, to convert to ALLCAPS after the user leaves the field. In practice, the effect is the same. Also, it is much less buggy and much more browser-independent.
> I have a unique problem.. I need to convert data entered in a text box to be displayed in CAPS.
This isn't really unique - we do it all the time in the midrange world. To do it properly, you need modifieable events, which are only available in the IT DOM. If you're willing to stick with IE, here's a simple toUpper() function:
key = window.event.keyCode;
if ((key > 0x60) && (key < 0x7B)) window.event.keyCode = key-0x20;
Connect this to the onKeyPress event.