Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Calculating 2 fields without a script error.

Avatar

Level 3

Is there a way to make a calculation of two fields not calculate until the 3rd field is reached.  I have a calculation that takes (field1/field2)*100.  Once the user puts in field1, it throws a script error, which is annoying.  Anyway around this???

Thanks for your help.

1 Accepted Solution

Avatar

Correct answer by
Level 10

You need to test to make sure there is a value in the fields first.

Using FormCalc:

if (HasValue(field1) and HasValue(field2)) then

    $ = field1 / field2 * 100

endif

Or JavaScript:

if (!field1.isNull && !field2.isNull) {

     this.rawValue = field1.rawValue / field2.rawValue * 100;

}

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

You need to test to make sure there is a value in the fields first.

Using FormCalc:

if (HasValue(field1) and HasValue(field2)) then

    $ = field1 / field2 * 100

endif

Or JavaScript:

if (!field1.isNull && !field2.isNull) {

     this.rawValue = field1.rawValue / field2.rawValue * 100;

}

Avatar

Level 3

Jono - thank you so very much!  That worked like a charm.

I really wish I could pick up some more scripting knowledge!

Gretchen