Sonia,
You might like to try something like this:
//This is a general utility function that returns an Initial Caps version of the input string
function initialCaps(str){
var a = str.split(' ');
for(var i=0; i<a.length; i++){
ch = a[i].charAt(0);
a[i] = a[i].replace(ch, ch.toUpperCase());
}
return a.join(' ');
}
//This function is applies initialCaps() to a specified form field.
function field2InitialCaps(filedId){
var f = document.getElementById (filedId);
if(f) { f.value = initialCaps(f.value); }
}
<!-- Demo -->
<input id="txtCompanyName" type="text" value="sonia is a beautiful name" size="50" /><br />
<a href="" onclick="field2InitialCaps('txtCompanyName');return false">Convert to Initial Caps</a>
Airshow
Reputation Points: 318
Solved Threads: 358
WiFi Lounge Lizard
Offline 2,526 posts
since Apr 2009