Level 1

0% to

Level 2

Tip /

to gain points, level up, and earn exciting badges like the new
Mission!

View all

## I need help with a script

jeanette614
Level 3

Likes

5 likes

Total Posts

129 posts

1 solution
View profile

jeanette614
Level 3

Likes

5 likes

Total Posts

129 posts

1 solution
View profile
jeanette614
Level 3

20-05-2011

I have a form where I need one field to subtract from another but never show a negative number in the result field. So if the first field AsstsMo1 is \$100 and the second field SubDis1 is \$200, I don't want the negative \$100 to show in the total field but to display a zero instead.

This is what I have so far in FormCalc. It works but doesn't display a zero in the field where it should but does display a zero in a field that calculates off this field. So the field is called Excess1 and that's where the script is assigned to and later on in the form, a total field calls for Excess1 to be added to MonthlyExcess1 and that's where the zero displays which is perfect. I just can't get the first field to display that zero. Right now it displays nothing.

if(SubDis1 >= AsstsMo1) then \$.rawValue = AsstsMo1 - AsstsMo1 else \$.rawValue = AsstsMo1 - SubDis1 endif

Can you help?

### Replies

Niall_O_Donovan
Level 10

Likes

646 likes

Total Posts

4,352 posts

786 solutions
View profile

Niall_O_Donovan
Level 10

Likes

646 likes

Total Posts

4,352 posts

786 solutions
View profile
Niall_O_Donovan
Level 10

20-05-2011

Hi,

The script looks okay-ish, I am just replicating it here with some amendments:

if (SubDis1 ge AsstsMo1) then

\$ = 0

else

\$ = AsstsMo1 - SubDis1

endif

In FormCalc the equivalent operator is "ge" for greater than or equal to. Make sure that the language is set to FormCalc.

Give that a try,

Niall

jeanette614
Level 3

Likes

5 likes

Total Posts

129 posts

1 solution
View profile

jeanette614
Level 3

Likes

5 likes

Total Posts

129 posts

1 solution
View profile
jeanette614
Level 3

20-05-2011

That gave me quite a few errors when I opened it in Acrobat Pro and still didn't display a zero.  Here is what it displayed:

Script failed (langage is formCalc; context is xfa[0].form[0].form1[0],Page [0].Spenddown[0].Excess1[0])

script= (then the script)

Error: syntax error near token "on line 2, column 4294957295 (whatever that means)

Niall_O_Donovan
Level 10

Likes

646 likes

Total Posts

4,352 posts

786 solutions
View profile

Niall_O_Donovan
Level 10

Likes

646 likes

Total Posts

4,352 posts

786 solutions
View profile
Niall_O_Donovan
Level 10

20-05-2011

Hi,

If you open the JavaScript Console it may show the error in more detail:

From the error we know that you have the correct language.

The problem is on line 2. I would recommend that you go to the Script Editor and click on the Check Syntax button above the script editor. This should hlightline the error in red. Also if you go to the Warnings palette you may get further information there.

The script doesn't have a double quotation mark, so unless there is a stray one in the script it is difficult to see ehat is wrong.

Niall

jeanette614
Level 3

Likes

5 likes

Total Posts

129 posts

1 solution
View profile

jeanette614
Level 3

Likes

5 likes

Total Posts

129 posts

1 solution
View profile
jeanette614
Level 3

20-05-2011

Sure, how do I do that?

Niall_O_Donovan
Level 10

Likes

646 likes

Total Posts

4,352 posts

786 solutions
View profile

Niall_O_Donovan
Level 10

Likes

646 likes

Total Posts

4,352 posts

786 solutions
View profile
Niall_O_Donovan
Level 10

20-05-2011

Hi,

You can upload it to Acrobat.com and then post your published file URL here:

Niall

jeanette614
Level 3

Likes

5 likes

Total Posts

129 posts

1 solution
View profile

jeanette614
Level 3

Likes

5 likes

Total Posts

129 posts

1 solution