Form Calculator BETA

(has a known issue with negative numbers)

The Form Calculator Action will help you to add, subtract, multiply, divide and calculate percentages for values entered into an HTML form. The results of the math calculations can be stored as variables, displayed in a layer or div, or written into other form fields for display or use in other calculations.

There are two main numbers being calculated. Either number can be read from a form field, a stored variable, a static entered value (such as sales tax percent), or the sum of any combination of those sources.

If you haven't already, you'll first need to download a copy of the action file.

Decompress the ZIP file and put it into a new folder named "MindPalette" (if you don't already have a MindPalette folder in your GoLive actions). Put the MindPalette folder into your GoLive actions folder, which you can find here on your computer:

(Main GoLive Folder) / Modules / JScripts / Actions

Afte installing the action, be sure to restart GoLive so the action will be available for use.

To use the action, you'll first need to apply it to an event. For instance, if you want the calculation to happen when the form is submitted, select the form container in GoLive and open the Actions palette (Window > Actions from the top menu, or Window > Rollovers and Actions in GoLive CS). At the top left of the actions palette, choose the appropriate event ("Form Submit" in this example).

With the event selected, add a new action on the right side of the palette by clicking the "Create New Action" icon below (looks like a page with a turned up corner). From the Action menu below, choose the Form Calculator action (from the MindPalette group, if you put it in a MindPalette folder).

The entry fields and setting for this action should then appear in the Actions palette. The options are all described below.

form name
Enter the name of your HTML form. All fields being calculated will need to be in the same form.

FIRST NUMBER (x)

The next three settings will determine the first number used in the math operation. If more than one variable type is used (form field, static or variable value), the sum of all entries will be used as the first number.

form field names(s)
Enter the name of your form field that contains your first number, or enter a list of form fields separated by commas. If more than one form field name is entered, the action will use the sum of the entered fields.
static value
If you'd like to use a set value in the calculation instead of the value of a form field, enter that value here.
stored variable name
If you'd like to use the result of a previous operation in this action, then enter the name of the variable used to store the former result.

OPERATION

The next setting (operation) determines the simple math formula used to calculate your total.

operation
  1. add (x+y):
    add the values of the first and second number.
  2. subtract (x-y):
    subtract the second number from the first.
  3. multiply (x*y):
    multiply the first number by the second.
  4. divide (x/y):
    divide the first number by the second.
  5. + percent (x+(x*(y/100))):
    add y percent of x to x.
  6. - percent (x-(x*(y/100))):
    subtract y percent of x from x.

SECOND NUMBER (y)

The next three settings will determine the second number used in the math operation. They work just like the "form field names", "static value" and "stored variable name" field used for the first number. If you're just doing simple addition, you don't need to enter anything for the second number since the sum of any fields entered for the first number is already being calculated.

FORMAT RESULTS

The next five fields are used to format the results of the calculation. Round the results (round off, round up or round down), force a specified number of decimal places (a setting of 2 would convert 32.1 to 32.10), add commas to separate thousands, or use the absolute result (-132 or 132 = 132).

WRITE RESULTS TO

text or hidden field
This option will write the formatted results into a text field or hidden field. In most cases, if writing the result to a text field, it's best to set the fied to "read only" in the Inspector so the results can't be changed manually.
DIV or layer ID
If you'd like the results to be written as text into a GoLive Layer or <div> with a specified ID, enter the ID into this field.
store in variable
If you'd like to save the results of your calculation for later use, enter the name of your variable here. The value entered here will be the same used in the "stored variable name" fields above in later calculations. The variable name should only contain letters, numbers or underscores (no spaces, punctuation or special characters).

Your action should now be ready for testing. When adding a new action to your site, particularly in GoLive CS2, you should always flatten and re-upload your site's GeneratedItems/CSScriptLib.js file to be sure GoLive refreshes its script library to include the code needed for the action. To flatten the script library, right click (or control+click on Mac) the CSScriptLib.js file (inside the GeneratedItems folder at the top level of your site) and choose Flatten Script Library (or Update > Flatten Script Library in GoLive CS2).

If you have any trouble, please consult the Actions FAQ here:
www.mindpalette.com/actions/faq.php

...or post a question in our online support forum:
www.mindpalette.com/forum

[ back to top ]