Convert to uppercase as user types using javascript

Butcher picture Butcher · Apr 6, 2011 · Viewed 99.8k times · Source

I want to convert lowercase chars to uppercase as the user types using javascript. Any suggestions are welcome.

I have tried the following:

$("#textbox").live('keypress', function (e) {
    if (e.which >= 97 && e.which <= 122) {
        var newKey = e.which - 32;
        // I have tried setting those
        e.keyCode = newKey;
        e.charCode = newKey;
    }
});

Answer

kennebec picture kennebec · Apr 6, 2011
css

#textbox{text-transform:uppercase}