NetTalk Web Server > Web Server - Share Knowledge

Capitalize Input

(1/2) > >>

Alan Cochran:
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

Rene Simons:
Alan,
Interesting but can you show me some screenshots on how to add the code to the global var declaration??
Thanks,
René

mriffey:
in the initial value, paste the info inside the single quotes.

Mark

mriffey:
Alan,

Not sure why, but Im unable to get this to work on 4.28. The Uppercase stuff works fine.

Any ideas?

Mark

mriffey:
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

Navigation

[0] Message Index

[#] Next page

Go to full version