NetTalk Central

Author Topic: passing javascript values on forms  (Read 5294 times)

mriffey

  • Newbie
  • *
  • Posts: 43
    • View Profile
    • Email
passing javascript values on forms
« on: August 16, 2007, 05:21:33 PM »
Bruce,

The inline javascript Ive tried works fine, but for some reason, I cannot get the functions like the one Alan Cochran did (and others built like it) to work. It's like they don’t have access to this.value or something.

function toProperCase(s)
{
  return s.toLowerCase().replace(/^(.)|\s(.)/g,
          function($1) { return $1.toUpperCase(); });
}

This is one Bob found on the net (at http://www.codeproject.com/jscript/propercase.asp ) that works fine in a regular page, but I cannot get it to return a capitalized value - or ANY value for that matter.

At one point, I had it doing this, just to see if it would give me anything.

In the validation field in the Nt4 app for this field, it says 'toProperCase(this.value);'

function toProperCase(s)
{
  var txtstr = s;
  txtstr.toUpperCase();
  alert('after upper ' + txtstr);
  txtstr.toLowerCase();
  alert('after lower ' + txtstr);
  txtstr.toLowerCase().replace(/^(.)|\txtstr(.)/g,
          function($1) { return $1.toUpperCase(); });
  alert('after replace ' + txtstr);
  return txtstr;
}

When I type "firstname" in the field and press tab, the alerts produced these messages:
 after upper firstname
 after lower firstname
 after replace firstname

IE: none of the toUpperCase stuff ever took. Tested on FF 2.006 and IE7 on Vista. Same results.

Clearly I missing something. Got an idea what it might be?<g>

Mark

Alan Cochran

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: passing javascript values on forms
« Reply #1 on: August 16, 2007, 09:17:09 PM »
Mark,

Make sure under the Client-Side tab for the Field is that you make the call to the java script function for each field that needs to run the function. Also, remember that the Hand Code Support (Set Dynamic) Field is checked along with Reset Other Field for the current field (value) is checked.  (See Fields.png Image)

You will notice I have placed the global variable (js:capitalize) in the Java Hand-Code field instead of the actual javascript function.  I placed the javascript function name in the Initial Value field of the global variable  --  capitialize(this);   along with the THREAD option Checked. (See GlobalVariable.png Image).  In your case you would have toProperCase(this); in this field. 

I also believe the javascript function name are Case-Sensitive so be sure to check everything matches. 

Try using this function.  I changed the function name to the name that you have used in your app. 

function toProperCase(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;;
}


This has been tested under Vista and XP Pro using both IE6, IE7 and FF 2.0.0.6

HTH...
Alan

[attachment deleted by admin]
« Last Edit: August 16, 2007, 09:37:07 PM by Alan Cochran »

mriffey

  • Newbie
  • *
  • Posts: 43
    • View Profile
    • Email
Re: passing javascript values on forms
« Reply #2 on: August 17, 2007, 06:42:10 AM »
Thanks Alan. Unfortunately, I still cant get it to do anything to the field. Its like its getting lost during the replace. The only difference in what you and I had was that I didnt have the global threaded (it is now).

I put an alert(val); before the obj.value=val; line and it didnt display.

Then I put one after the toLowerCase and another after the if (!val) and neither one of THOSE displayed. I may just have to do this server-side, I guess.

Mark