I have input
and I want it to only allow capital letters in real time.
This code seems to work perfectly.
$("#texto").on("input", function(){
$(this).val($(this).val().toUpperCase());
});
But I noticed a bug and I do not know how to solve it:
When I have text for example "RIO JANEIRO" and I want to correct it for "RIO DE JANEIRO", when I type any letter in the middle of the word the input cursor is reset and goes to the last character and then the text is thus "RIO D JANEIROE". Notice that the first letter is in the correct place and then the cursor is moved to the end.
How can I resolve this?
$("#texto").on("input", function(){
$(this).val($(this).val().toUpperCase());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputtype="text" id="texto">