Input toUpperCase correct on desktop, on mobile with duplicate error

1

The script below transforms all uppercase characters into an input.

<input type='text' name='meuInput'>

<script>
  $("input").bind('keyup', function (e) {
    if (e.which >= 97 && e.which <= 122) {
      var newKey = e.which - 32;
      e.keyCode = newKey;
      e.charCode = newKey;
    }
    $(this).val(($(this).val()).toUpperCase());
});
</script>

On the desktop it works normally, but on mobile it doubles the text. But on mobile when:

Type: E

Sai: EE

Type: E is

Sai: And he is

I type: And it's a

Exit E is aE is aE is a

Is there another way or how to fix this?

    
asked by anonymous 13.12.2017 / 18:20

1 answer

3

In fact your code transforms the characters of only one input, but of all. And you do not need a javascript for this, just the css text-tranform.

Here is an example where all text inputs will have their contents in uppercase.

input[type='text']{
  text-transform: uppercase;
}
<input type='text' name='meuInput'>
    
13.12.2017 / 18:31