heres my onBlur function to change the first letter of each word to uppercase.
function toUpper(value) {
var pattern = /(\w)(\w*)/; // a letter, and then one, none or more letters
var a = value.split(/\s+/g); // split the sentence into an array of words
for (i = 0 ; i < a.length ; i ++ ) {
var parts = a.match(pattern); // just a temp variable to store the fragments in.
var firstLetter = parts[1].toUpperCase();
var restOfWord = parts[2].toLowerCase();
a = firstLetter + restOfWord; // re-assign it back to the array and move on
}
value = a.join(' '); // join it back together
return value;
}
It works fine in fireFox, but in IE if the form fields are empty, i get this error:
### ERROR ###
'1' is null or not an object at line 'var parts = a.match(pattern);'
### ERROR ###
The script carries on with the error, but i need to know how elimate this bug.
Thanks.
function toUpper(value) {
var pattern = /(\w)(\w*)/; // a letter, and then one, none or more letters
var a = value.split(/\s+/g); // split the sentence into an array of words
for (i = 0 ; i < a.length ; i ++ ) {
var parts = a.match(pattern); // just a temp variable to store the fragments in.
var firstLetter = parts[1].toUpperCase();
var restOfWord = parts[2].toLowerCase();
a = firstLetter + restOfWord; // re-assign it back to the array and move on
}
value = a.join(' '); // join it back together
return value;
}
It works fine in fireFox, but in IE if the form fields are empty, i get this error:
### ERROR ###
'1' is null or not an object at line 'var parts = a.match(pattern);'
### ERROR ###
The script carries on with the error, but i need to know how elimate this bug.
Thanks.