Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Zero if negative number

Avatar

Level 4

I am trying to get a form to show a zero if the number subtracted results in a negative.

ie $100 - $200 = $0

Please help the scripting afflicted.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

The script in the calculate event of the numeric field would need an if/else statement. For example (using JavaScript):

var nAns = NumericField1.rawValue - NumericField2.rawValue;

if (nAns >= 0) {

     this.rawValue = nAns;

}

else {

     this.rawValue = 0;

}

Hope that helps,

Niall

View solution in original post

4 Replies

Avatar

Correct answer by
Level 10

Hi,

The script in the calculate event of the numeric field would need an if/else statement. For example (using JavaScript):

var nAns = NumericField1.rawValue - NumericField2.rawValue;

if (nAns >= 0) {

     this.rawValue = nAns;

}

else {

     this.rawValue = 0;

}

Hope that helps,

Niall

Avatar

Level 4

Correct as always. Thanks, Niall.

I have little scraps of paper with your scripts on them taped all over the walls of my office. They always did think I was strange here.

Your friend, Cake Diva

Avatar

Level 10

...I'll just have to turn those scraps into a book!