I am trying to make a textarea that only will type in caps, even if the user isn't holding down shift or has caps lock on. Ideally this would accept the input no matter what and just automatically shift it to all caps. Most of the ways I am thinking of seem kind of clunky and would also show the lowercase before it gets converted.
Any suggestions or strategies?
Use keyup() method to trigger the keyup event when user releases the key from keyboard. Use toLocaleUpperCase() method to transform the input to uppercase and again set it to the input element.
<input ... pattern="[a-zA-Z]*" ...>
With the text-transform property, you can style your text content as all lowercase , all uppercase , or capitalize only the first letter of each word. You can include as many words as you need to uppercase inside the <span> tag.
You can achieve CSS all caps by using the keyword “capitalize.” In addition, text-transform capitalize converts all the first letters in all words to uppercase. Other values you can use with text-transform include “none,” “lowercase,” “full-width,” and “full-size-kana.”
you can use CSS
textarea { text-transform: uppercase; }
however, this only renders on the browser. let's say if you want to inject the text into a script or db in the textarea as all caps then you'll have to use javascript's toUpperCase();
before injection or form submit.
here is the jsfiddle for example:
html:
<textarea>I really like jAvaScript</textarea>
css:
textarea{ text-transform: uppercase; }
javascript:
var myTextArea = document.getElementsByTagName('textarea'); for(var i=0; i<myTextArea.length; i++){ console.log('Textarea ' + i + ' output: ' + myTextArea[i].innerHTML); //I really like jAvaScript console.log('Textarea ' + i + ' converted output: ' + myTextArea[i].innerHTML.toUpperCase()); //I REALLY LIKE JAVASCRIPT }
CSS:
textarea { text-transform: uppercase; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With