NetTalk Central
NetTalk Web Server => Web Server - Share Knowledge => Topic started by: Alan Cochran on July 27, 2007, 06:55:54 AM
-
Hi All,
To capitalize the first letter in each word of an input, do the following:
1) Create or modify your custom js file and place the following function in it. (Be sure that the js file has been added in the scripts section of the NetTalk or NetSimple Object extension template under WebServer procedure).
function capitalize(obj) {
var val = obj.value.toLowerCase();
if(!val) return;
val=val.replace(/\b([a-z]+)\b/ig,function(w){
return w.charAt(0).toUpperCase()+w.substring(1);
});
obj.value=val;;
}
2) Create global variable - js:capitalize STRING('capitalize(this);')
3) In the entry field properties, client tab put that variable (no quotes) in the javascript hand-code entry filed (the onchange group). Be sure to check the Field check box under the Hand Code Support option. Also, under the Reset Other fields, add the field you are wanting to Capitalize with the Value checked.
The field will be made Capitalize when the user tabs off it.
Alan
-
Alan,
Interesting but can you show me some screenshots on how to add the code to the global var declaration??
Thanks,
René
-
in the initial value, paste the info inside the single quotes.
Mark
-
Alan,
Not sure why, but Im unable to get this to work on 4.28. The Uppercase stuff works fine.
Any ideas?
Mark
-
Been beating on this a while, anyone got a clue why this doesnt work just to cap the first letter?
'var str = this.value;str[0] = str[0].toUpperCase();this.value = str'
if I put alerts in, they show the right value, but it never goes to upper case.
Mark
-
Hi Mark,
your javascript is wrong. It should be
'var str = this.value; str = str[0].toUpperCase() + str.substr(1);
this.value = str; alert(this.value);'
which incidentally can be reduced to
'this.value = this.value[0].toUpperCase() + this.value.substr(1);'
Cheers
Bruce
-
thanks Bruce.
Mark