Expand my Community achievements bar.

SOLVED

I have a dollar amount box x 26 = Annual Payroll Deduction

Avatar

Level 2

I have a dollar amount box x26 = annual payroll deduction and tried to write a java script to automatically come up with the annual payroll deduction and I keep getting error messages.  I am using the annual payroll deduction in another calculation which works could that be the problem?  Does anyone have a sight were I can read to find out what I am doing wrong?

1 Accepted Solution

Avatar

Correct answer by
Level 7

Here you go. I put the script in the calculate event of F1. When doing any scripting it's important to match the syntax of the field name exactly. When working with whatever value is in the field, the correct syntax is fieldName.rawValue (i.e., F1.rawValue, F9.rawValue). I also renamed f9 to F9. There's no real reason to do this other than for your own convenience, to be consistent with your fieldnames.

View solution in original post

10 Replies

Avatar

Former Community Member

Can you post the error message so we can see what the message is?

Paul

Avatar

Level 2

Script failed (lanuage is formcalc; context is

xfa[0].form[0].topmostSubform[0].page1[0].F1[0]

Script=ifN1=N9*N10 end if

Error;syntax error near token 'N1' on line 1, column 5

Avatar

Former Community Member

That is not a valid syntax ......it shoudl look like this:

if (whatever your condition you are testing is) then

     N1=N9*N10

endif

Paul

Avatar

Level 2

Obviously I am very new at this.  What is "Whatever your dondition you are testing is"?

Avatar

Level 7

The condition you're testing for is whatever let's you know that you want to multiply N9*N10. So if that only applies to people who make more than $50,000/year then your script would be:

if (income > 50000) then

     N1 = N9 * N10

endif

In this case, the condition being tested is whether or not the user's income is greater than $50,000.

Avatar

Level 2

What if it is a simple equation.  There are no conditions it is whatever the user puts, how much they want deducted from the paycheck times the 26 weeks.  It could be any number.

Avatar

Level 7

You would use the name of the deduction field in your equation, something like:

this.rawValue = (deduction.rawValue * 26);

for javaScript, or:

this.rawValue = deduction * 26

for FormCalc

Avatar

Level 2

No won't work.  Can you look at it and see what I am doing wrong?

Avatar

Correct answer by
Level 7

Here you go. I put the script in the calculate event of F1. When doing any scripting it's important to match the syntax of the field name exactly. When working with whatever value is in the field, the correct syntax is fieldName.rawValue (i.e., F1.rawValue, F9.rawValue). I also renamed f9 to F9. There's no real reason to do this other than for your own convenience, to be consistent with your fieldnames.

Avatar

Level 2

Thank you so much I learned a lot.  Is there somewhere you can learn these things or a book you know of?