NetTalk Central

Author Topic: Capitalize Javascript Function  (Read 5706 times)

Alan Cochran

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Capitalize Javascript Function
« on: July 25, 2007, 07:42:29 PM »
Hi All,

Has anybody had any luck with calling a Capitalize Javascript function via an input field?  I am able to run an UPPERCASE and LOWERCASE functions with no problem based on Chris Laurie's example but having problems with a Capitalize function.  I would like to make sure certain fields have the Mixed case capability in different forms. So it would be nice to have one function to accomplish this.

Currently, I have created a JS file with the following:

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;;
}


In the Client-Side tab under the Fields option I have in the "When Field Accepted in Browse (onChange)" Javascript HandCode field -  'capitalize(this)'  for the field that I want to call this function.  This is probably my problem since I believe I am not calling this function correctly.  I would appreciate any help on this. I have several forms that I need to make this function call.

Thanks for any help or suggestions on this.
Alan

Alan Cochran

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: Capitalize Javascript Function
« Reply #1 on: July 27, 2007, 06:52:53 AM »
Hi All,

I have figured out on how to call a javascript function to Capitalize an input field. I want to thank Chris Laurie's message (Uppercase Input) in guiding me in the right direction.

Here are the steps to do it:

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