Expand my Community achievements bar.

SOLVED

## If total is over 100%, delete last entered value

Level 1

Hi, hope you are safe and sound.

I have 5 numeric fields, formatted as "%". Display patter: num{9.8'%'}|num{99.8'%'}

Each field is limited to max. two characters with below script on change event:

if (xfa.event.newText > 99) {
xfa.event.change = "";
}

6th field is "Total", where sum is calculated for those 5 fields. Calculate event for the "Total" field:

this.rawValue = form1.Page1.Subform13.Subform14.Table4.Row1.Percent1.rawValue + ... form1.Page1.Subform13.Subform14.Table4.Row2.Percent5.rawValue;

Is it possible to go through all 5 fields and delete only the value from the field I'm currently in, if the "Total" is exceeding 100%? e.g.

"Percent1" = 55% + "Percent3" = 60%   -- delete 60% from Percent3

"Percent3" = 25% + "Percent5" = 70% + "Percent4" = 6%  -- delete 6% from Percent4

"Percent5" = 35% + "Percent2" = 90%   -- delete 90% from Percent2

like, any field combination and in any order?

Thanks

1 Accepted Solution

Employee

Add this script on the exit event of each numeric field:

```if (Total.rawValue>100)

this.rawValue=0;

// OR (Use any one of these which is applicable)

this.rawValue="";```

2 Replies

Employee

Add this script on the exit event of each numeric field:

```if (Total.rawValue>100)

this.rawValue=0;

// OR (Use any one of these which is applicable)

this.rawValue="";```

Level 1

Thank you very much Mayank.

For my case it worked with:

`this.rawValue="";`

Here is how it works, for everyone interested.

1. A single column of five Numeric fields, all have applied num{9.8'%'}|num{99.8'%'} Display pattern.

2. All five have a script on change event (allow max. two characters)

```if (xfa.event.newText > 99) {
xfa.event.change = "";
}```

3. Again, all five have on the exit event this script:

```if (form1.Page1.Subform15.Total.rawValue>100)
this.rawValue="";```

4. A numeric field named "Total", has this display patter num{9.8'%'}|num{99.8'%'}|num{999.8'%'} applied, and on calculate event script:

`this.rawValue = form1.Page1.Subform13.Subform14.Table4.Row1.Percent1.rawValue + ... + form1.Page1.Subform13.Subform14.Table4.Row5.Percent5.rawValue`

Thats it.

Thanks again.