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.

form logic calculation

Avatar

Level 1

Upfront,  I'm an Adobe Noob.  I can stumble my way through most of the things I do not know how to do but I am stuck on this one.

The situation.   I have a form that includes filled by the user.  These fields are "Purchase Price", "Less Concessions", "Less Home Warranty",  "LAComm" & "BAComm".    All are numbers.  I also have a drop down box where the user selects "Commission Based On:" and their choices are "Net" or "Gross".   Once the user inputs Purchase Price, Less Concessions & Less Home Warranty I have the form calculate the ""NetPurPrice".  That is easy. 

The Problem.   I have two fields that need a logical calculation.  "BuyComDue" & "ListComDue".  If the user selects Net from the drop down menu the "ComDue"s are based off of the NetPurPrice.  And obviously if the user selects Gross then we base the "ComDue"s on the PurchsePrice.

So how do I make the form do the following:

IF "Commision Based On" = Gross

     THEN "BuyComDue" = "PurchasePrice" x "BAComm"

     AND   "ListComDue" = "PurchasePrice" x "LAComm"

ELSE

     "BuyComDue" = "NetPurPrice" x "BAComm"

     AND   "ListComDue" = "NetPurPrice" x "LAComm"

SideNote:   Currently to get my NetPurPrice the user is forced to enter a negative value in "LessConcessions" & "Less Home Warranty".  I have the form forcing a neg. number using validation.  It works but I would like to make the form do subtraction vs. adding neg. numbers to reach my goal.  It would seem more user friendly.

Thank you for any and all assistance you provide.

5 Replies

Avatar

Level 1

That is sort of what I figured. but using the following....

IF ( CommBase = Gross ) BuyComDue = PurchasePrice * BAComm

ELSE BuyComDue = NetPurPrice * BAComm

I receive...

SyntaxError: missing ; before statement

1: at line 2

I have tried everything. 

Avatar

Level 4

That is not how you access fields' values. Read the last part of the second tutorial I linked to.

Also, it's not how you write the JavaScript code. JS is case-sensitive. So you have to use "if", not "IF", and "else", not "ELSE", etc.