Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a textarea all caps?

Tags:

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?

like image 480
Quintin Avatar asked Feb 09 '11 00:02

Quintin


People also ask

How do you automatically set text box to uppercase?

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.

How do you input all caps?

<input ... pattern="[a-zA-Z]*" ...>

How do you make all caps in HTML?

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.

How do you make all letters capital in CSS?

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.”


2 Answers

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 } 
like image 171
KJYe.Name Avatar answered Nov 04 '22 19:11

KJYe.Name


CSS:

textarea { text-transform: uppercase; } 
like image 36
drudge Avatar answered Nov 04 '22 17:11

drudge