Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With jQuery, how do I capitalize the first letter of a text field while the user is still editing that field?

I'm looking for an example of how to capitalize the first letter of a string being entered into a text field. Normally, this is done on the entire field with a function, regex, OnBlur, OnChange, etc. I want to capitalize the first letter while the user is still typing.

For instance, if I'm typing the word "cat", the user should press 'c', and then by the time he presses 'a', the C should be capitalized in the field.

I think what I'm going for might be possible with keyup or keypress but I'm not sure where to start.

Anyone have an example for me?

like image 380
tresstylez Avatar asked Jan 07 '10 00:01

tresstylez


People also ask

How can I uppercase the first letter of a string in jQuery?

Answer: Use the toUpperCase() method.

How do you capitalize the first letter in a string JavaScript?

To capitalize the first character of a string, We can use the charAt() to separate the first character and then use the toUpperCase() function to capitalize it.


1 Answers

Just use CSS.

.myclass  {     text-transform:capitalize; } 
like image 127
NotMe Avatar answered Oct 03 '22 22:10

NotMe