Expand my Community achievements bar.

Calculation in Exit Event Problem

Avatar

Level 4

Hi,

I have a field called lifeCharge and it is calculated from the value of two other fields, allPlans30 or allPlans35. The calculation can only come from one or the other.  I have the default set at zero for allPlans30 and allPlans35. The calculation works fine, however, if I put an amount in field allPlans35 and tab out, it goes to the next field (allPlans30) and resets the amount in allPlans35. How do I prevent this from happening?  Thanks!

Per Life Charge        $____________

     All Plans ($35 x ________0)

     All Plans ($30 x ________0)

Script for allPlans35 in the exit event

if(this.rawValue != 0)

lifeCharge.rawValue = this.rawValue * 35;

allPlans30.rawValue = 0;

Script for allPlans30 in the exit event

if(this.rawValue != 0)

lifeCharge.rawValue = this.rawValue * 30;

allPlans35.rawValue = 0;

6 Replies

Avatar

Level 4

I tried another approach - I removed the scripts from allPlans35 and allPlans30 fields and added the following script in the lifeCharge field as a calculation event.

if

(allPlans30.rawValue == 0 || allPlans30.rawValue == null)

this.rawValue

= allPlans35.rawValue * 35;

else

if (allPlans35.rawValue == 0 || allPlans35.rawValue == null)

this.rawValue

= allPlans30.rawValue * 30;

Now what is happening is if you enter an amount in allPlans35 and change your mind and enter an amount in allPlans30, you have to manually delete the amount in allPlans35 to have the calculation work.  Is this the way is has to be or is there a better solution.

Thanks

Avatar

Level 10

Hi,

There are a couple of approaches.

I am inclined to suggest the following javascript in the calculate event of the lifeCharge object:

this.rawValue = (allPlans35.rawValue * 35) + (allPlans30.rawValue * 30); 

This is on the basis that the user can only place a value in allPlans35 OR allPlans30.

To achieve this have the following in the exit events:

allPlans 35 exit event:

if (this.rawValue != null) // allPlans35

{

     allPlans30.rawValue = 0;

}

allPlans 30 exit event:

if (this.rawValue != null) // allPlans30

{

     allPlans35.rawValue = 0;

}

Hope that helps,

Niall

Assure Dynamics

Avatar

Level 4

Hi Niall,  thanks for your response.  This does work if I mouse exit out of field allPlans35, however, if I keep tabbing it clears them.

Avatar

Level 10

Hi,

I am going to suggest a FormCalc script for the two exit events:

// if this field has a value, then clear the other field

if (HasValue($) and $ ne 0) then

     allPlans30.rawValue = 0

endif

Here is an example:

https://acrobat.com/#d=sTbpBqlVu6jFqqM7jvRG*A

Hope that helps,

Niall

Assure Dynamics

Avatar

Level 4

When I tab out of field allPlans35, it acts very slow and then when I tab out of field allPlans30 I get a Runtime Error and the form closes.

Avatar

Level 4

I think I got it.  I added the following script to the exit event of allPlans30 and allPlans35.

if

(this.rawValue != 0) //allPlans35

xfa.host.resetData("xfa.form.form1.allPlans30");

if

(this.rawValue != 0)//allPlans30

xfa.host.resetData("xfa.form.form1.allPlans35");