JavaScript
Article
By Sam Deering

Capitalize First Letter of Every Word on Keypress

By Sam Deering

jQuery code snippet to make capitals of the first letter of every word in the string. This could be used to prevent users from entering all caps for titles or text when they input data into forms.

//usage
$(“input”).keyup(function() {
toUpper(this);
});

//function
function toUpper(obj) {
var mystring = obj.value;
var sp = mystring.split(‘ ‘);
var wl=0;
var f ,r;
var word = new Array();
for (i = 0 ; i

--ADVERTISEMENT--

Login or Create Account to Comment
Login Create Account
Recommended
Sponsors
Get the most important and interesting stories in tech. Straight to your inbox, daily.