Help with Botox Injection Calculation

Please help me improve this!
I have it set where I can input the number of areas treated and it will add the appropriate number of lines.
I want it to calculate the total number of units after I input the units per area.
I also want it to calculate the total price and still allow me to choose the price per unit (it varies based on brand).

Product: {formmenu: default=Xeomin; Dysport; Daxxify; Botox; name=Product Used}
Expiration: {formtext: name=Exp; default=/2026}
Lot: {formtext: name=Lot}

Areas treated:
{note: trim=left} {formtext: name=#areas; default=1}
{endnote: trim=right}
{repeat: for i in (seq(1, `#areas`) if `#areas` > 0 else )}
{formmenu: values={=areas}; name=Location} - {formtext: name=Units #; cols=5} Units
{endrepeat}
{note: trim=left; preview=no}
Areas: {areas=["Frontalis", "Glabella", "Crow's Feet (total)", "Crow's Feet - Left", "Crow's Feet - Right", "Bunny Lines", "Brow Lift", "Gummy Smile", "Lip Lift", "DAOs", "Masseter - Left", "Masseter - Right", "Chin", "Platysma", "Axillary Hyperhydrosis", "Other"]}
{endnote: trim=right}

Total Units: ? formula
Price per unit: {formmenu: 15; default=13; 12; 9; 6; name=Price; trim=no}
Total Price = Price * Total Units

Hi, Jessica !
I can probably help but I'll need more clarity.

Can you provide a finished example of what the output text and results would look like ? One done "by hand".
(please put in bold or red the elements that would be calculated/processed by your snippet)

And the numbers that would go in, for that result ??
Based on text and snippet, I identified two working variable, among the others. If I missed others, please add them as well.

  • The number of areas total
  • The number of unit, in each area (in the repeat section)

With the total unit number expected to be calculated by the snippet, right ?

Thanks,

Hi @Jessica_R
If I undersatnd you correctly, the example below is how you would do it. It gives some error messages because some characters are not escaped correctly, but you'll see what I'm doing.
Overall:

  1. Add a locale setting to the repeat command to allow iterating through the form field values
  2. Reducing the list of Units # to sum them up

Product: {formmenu: default=Xeomin; Dysport; Daxxify; Botox; name=Product Used}
Expiration: {formtext: name=Exp; default=/2026}
Lot: {formtext: name=Lot}

Areas treated:
{note: trim=left} {formtext: name=#areas; default=1}
{endnote: trim=right}
{repeat: for i in (seq(1, #areas) if #areas > 0 else ); locals=units}
{formmenu: values={=areas}; name=Location} - {formtext: name=Units #; cols=5} Units
{endrepeat}
{note: trim=left; preview=no}
Areas: {areas=["Frontalis", "Glabella", "Crow's Feet (total)", "Crow's Feet - Left", "Crow's Feet - Right", "Bunny Lines", "Brow Lift", "Gummy Smile", "Lip Lift", "DAOs", "Masseter - Left", "Masseter - Right", "Chin", "Platysma", "Axillary Hyperhydrosis", "Other"]}
{endnote: trim=right}

Total Units: {total units=reduce(units, 0, (x,y)->x + y["units #"])}{=total units}
Price per unit: {formmenu: 15; default=13; 12; 9; 6; name=Price; trim=no}
Total Price = {=Price * Total Units}