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