By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,490 Members | 1,417 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,490 IT Pros & Developers. It's quick & easy.

Getting and Setting key character in key event

P: n/a
I have had this function work perfectly in IE and am trying to get it
to work in Firefox. I have seen plenty of questions and answers on the
web for how to get and check the key pressed but nothing about setting
or changing it. I only want uppercase characters in this case. If the
key is a lowercase, it needs to be changed to an uppercase character.
IE lets you use keyCode to change the character code. How do I do the
equivalent in Firefox?

<textarea cols="40" rows="3" name="Rule" id="Rule"
onkeypress="checkUppercase(event);"></textarea>

function checkUppercase(e) {
// Get ASCII value of key that user pressed
if (!e) e = window.event;
var key = e.keyCode ? e.keyCode : e.which;

// Was key that was pressed a lowercase letter from a-z or backspace?
if ( key < 97 || key 122 || key == 8 )
return; // if so, do nothing
else // make it uppercase
if (window.event)
e.keyCode = key - 32; // IE
else
// None of the following work for Firefox
e.which = key - 32;
e.charCode = key - 32;
}

Thanks,
Jeff

Aug 17 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Thanks for the replies. I want to do the same thing in Firefox that
happens in IE, and that is changing the character as it is typed so
that means not using the onchange event. Is there no way to do this in
Firefox?

In the meantime, thanks to a combination of replies, this will work,
although I still would like to do it character by character:

<textarea cols="40" rows="3" name="Rule" style="text-
transform:uppercase;"
onchange="this.value = this.value.toUpperCase();"></textarea>

Thanks,
Jeff

Aug 20 '07 #2

P: n/a
Jeff <dc******@hotmail.comwrote in news:1187622363.012098.95910
@i38g2000prf.googlegroups.com:
Thanks for the replies. I want to do the same thing in Firefox that
happens in IE, and that is changing the character as it is typed so
that means not using the onchange event. Is there no way to do this in
Firefox?

In the meantime, thanks to a combination of replies, this will work,
although I still would like to do it character by character:
doing it character by character will be infuriating to your users. try it
yourself. What happens when you try to backspace/enter a period/return
key, etc... It really interferes with the user experience IMHO. If you
must do it, try Richard's CSS solution, and then keep the javascript
relegated to the 'onchange'

Aug 20 '07 #3

P: n/a
On Aug 20, 11:56 am, Good Man <he...@letsgo.comwrote:
doing it character by character will be infuriating to your users. try it
yourself. What happens when you try to backspace/enter a period/return
key, etc... It really interferes with the user experience IMHO.
It has been working that way for over a year with no complaints from
the users. BTW, if anything other than a lowercase character is typed,
the function exits. The users are on an Intranet and as of right now
are only using IE but now we are making sure Firefox users will be
able to use the site. So I take it that there is no equivalent way in
Firefox to change the character typed like IE can do?
Aug 21 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.