Is it possible to change the character which has been entered on keypress, without doing it manually?
For example, if I want to force uppercase letters based on some condition, it'd be nice to do the following:
function onKeypressHandler(e)
{
if ( condition )
{
e.which -= 32;
}
}
But of course that doesn't work.
NOTE: This is not an across the board uppercasing, but only specific characters.
Maybe I want to say if ( e.which >= 97 && e.which <= 102 )
or if ( Wind.Direction == 'South' )
or whatever - the condition itself is not important, but the uppercasing must only apply to the current character not the entire input.
I can do it by manually appending the changed character, but this is an ugly and messy way of doing it, and probably slower than it could be.
function onKeypressHandler(e)
{
if ( condition )
{
$j(this).val( $j(this).val() + String.fromCharCode( e.which - 32 ) );
return false;
}
}
A specific flaw with this method - if selecting all input text and entering a key, if it drops into this then it doesn't remove existing content, but simply appends to the content the user wanted removed. (Would need to investigating detecting any selected text to solve that, which makes this one even uglier.)
Can anyone provide a better solution?