NetTalk Central

Author Topic: Capitalize Input  (Read 17471 times)

Alan Cochran

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Capitalize Input
« 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


Rene Simons

  • Hero Member
  • *****
  • Posts: 649
    • View Profile
Re: Capitalize Input
« Reply #1 on: August 12, 2007, 05:57:47 AM »
Alan,
Interesting but can you show me some screenshots on how to add the code to the global var declaration??
Thanks,
René
Rene Simons
NT14.14

mriffey

  • Newbie
  • *
  • Posts: 43
    • View Profile
    • Email
Re: Capitalize Input
« Reply #2 on: August 14, 2007, 03:31:26 PM »
in the initial value, paste the info inside the single quotes.

Mark

mriffey

  • Newbie
  • *
  • Posts: 43
    • View Profile
    • Email
Re: Capitalize Input
« Reply #3 on: August 14, 2007, 03:32:09 PM »
Alan,

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

Any ideas?

Mark

mriffey

  • Newbie
  • *
  • Posts: 43
    • View Profile
    • Email
Re: Capitalize Input
« Reply #4 on: August 14, 2007, 06:19:14 PM »
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

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11174
    • View Profile
Re: Capitalize Input
« Reply #5 on: August 14, 2007, 11:16:39 PM »
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

mriffey

  • Newbie
  • *
  • Posts: 43
    • View Profile
    • Email
Re: Capitalize Input
« Reply #6 on: August 15, 2007, 07:11:56 AM »
thanks Bruce.

Mark