Kylena
09-29-2003, 02:21 AM
Hi, I've the following code in my field
var pattern = /(\w)(\w*)/; // a letter, and then one, none or more letters
var a = document.forms[0].LName.value.split(/\s+/g); // split the sentence into an array of words
for (i = 0 ; i < a.length ; i ++ ) {
var parts = a[i].match(pattern); // just a temp variable to store the fragments in.
var firstLetter = parts[1].toUpperCase();
var restOfWord = parts[2].toLowerCase();
a[i] = firstLetter + restOfWord; // re-assign it back to the array and move on
}
document.forms[0].LName.value = a.join(' ');
var f = document.forms[0];
f.FullName.value = f.LName.value + " " + f.FName.value;
whereby document.forms[0] is equivalent to this.form.
It works, however, I'd like to modify it so that when users enter data in the field, not all capitals appear and not all lowercase letters.
Eg:
AT THE HOUSE would appear as
At the house
The above code would change it to
At The House (which is not what I want)
var pattern = /(\w)(\w*)/; // a letter, and then one, none or more letters
var a = document.forms[0].LName.value.split(/\s+/g); // split the sentence into an array of words
for (i = 0 ; i < a.length ; i ++ ) {
var parts = a[i].match(pattern); // just a temp variable to store the fragments in.
var firstLetter = parts[1].toUpperCase();
var restOfWord = parts[2].toLowerCase();
a[i] = firstLetter + restOfWord; // re-assign it back to the array and move on
}
document.forms[0].LName.value = a.join(' ');
var f = document.forms[0];
f.FullName.value = f.LName.value + " " + f.FName.value;
whereby document.forms[0] is equivalent to this.form.
It works, however, I'd like to modify it so that when users enter data in the field, not all capitals appear and not all lowercase letters.
Eg:
AT THE HOUSE would appear as
At the house
The above code would change it to
At The House (which is not what I want)