Last updated on May 11th, 2016 at 03:05 pm

VN:F [1.9.22_1171]
Rating: 7.3/10 (11 votes cast)

Capitalize first letter javascript

This is a simple tutorial which shows how to capitalize first alphabet or letter using javascript.
Say for instance you have a contact form in which it has an input field that requires the NAME of the user.
Names should always begin with CAPS and the user just like that entered his/her name in the field. Then our script will track that and automatically convert the first letter or alphabet in to uppercase.
For example if the name entered by user is gurera linda then our javascript will track this and convert the name into Gurera Linda.
Just use this script

function toUpper(mystring) {
var sp = mystring.split(' ');
var wl=0;
var f ,r;
var word = new Array();
for (i = 0 ; i < sp.length ; i ++ ) {
f = sp[i].substring(0,1).toUpperCase();
r = sp[i].substring(1);
word[i] = f+r;
newstring = word.join(' ');
document.getElementById('keyword').value = newstring;
return true;

And how to call this javascript. Its simple just use the onblur switch and call the fuction like this


So once this is inserted in the input tag it will look something like

<input onblur="toUpper(this.value);" autocomplete="off" id="keyword" size="50" type="text" name="txtAddManager" />

Thats all pretty simple right 🙂


VN:F [1.9.22_1171]
Rating: 7.3/10 (11 votes cast)
One thought on “Capitalize first letter Javascript”

Leave a Reply

Your email address will not be published. Required fields are marked *