Capitalize First Letter of Every Word on Keypress

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.


$(“input”).keyup(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