Search code examples
javascriptjqueryinputtoupper

perform toUpperCase() each time the content of an input field is changed


I want to perform toUpperCase() each time the content of an input field is changed. I mean not when the field lost focus, but each time a character is typed.

I try this which doesn't work (I'm fairly new to JQ)!

$(".myClass").change(function () {
        $(this).val().toUpperCase();
});

Besides the function is launched only on blur.

What's wrong?


Solution

  • $('.myClass').on('input', function() {
         $(this).val($(this).val().toUpperCase());
    });