How to convert input text to uppercase while typing using Javascript
Sometimes we need to force the input of text in uppercase in a text field so that the user can only add uppercase letters. With JavaScript, you can automatically convert the value of input when typing. Not only with JavaScript, but we will also discover three different ways to transform the text into uppercase when typing.
Method 1: With JavaScript
<input type="text" onkeyup="this.value=this.value.toUpperCase()"/>
Result |
---|
[st_adsense]
Method 2: With CSS
<input style="text-transform: uppercase" type="text" />
Method 3: With JQuery
$(document).ready(function(){ $('#myId').keyup(function(){ $(this).val($(this).val().toUpperCase()); }); });[st_adsense]