JS Concatenate?

Hi all,

Very likely a newbie question, but here goes. I have a field whose value is the sum of two other fields:

Field 1: txtAcademicsIP
Field 2: txtAcademicsMisc

These should sum to:

Field 3: txtAcademicsAR

I set up a function for Field 3, which is called like this: 'tnValue (Academics)'
function tnValue (abl) {
  return (txt + abl + IP.Value) + (txt + abl + Misc.Value);
}

Problem is that I'm getting script errors every time it's run, and I'm starting to think it's the concatenation in the function. I've tried quotes, literal values, and constants, but the errors persist.

Anyone have a similar problem? The alternative is manually typing the source as "txtAcademicsIP.Value + txtAcademicsMisc.Value" for each of 20 fields, which I'd like to avoid.

Comments

  • JavaScript doesnt allow constructing variables like that. Actually, most languages dont allow it. PHP is the only one that comes to mind that does.

    What you want to do is instead pass the field itself as a parameter:
    function tnValue( a, b)
    {
       return a.Value + b.Value
    }
    

    Then set up the field source as
    tnValue( txtAcademicsIP, txtAcademicsMisc)
    
  • Drfff...

    My only excuse is that PHP has spoiled me - just needed a second pair of eyes. :?

    I see how your code is working - thanks for the nudge.

    Cheers,

Leave a Comment