I need to have my users put numbers in a text field and then show a total amount. Can I do that?
The following instructions are addressed to the Quickmode but can also be used in Easy and Classicmode.
ADDITION : Example: number1 + number2 = total
- Create an element where a single price will be entered or selected (textfield and/or select-list allowing a
choice of one option only) with properties as follows:
Label: First Price
Name: number1
Go to the Advanced tab of the element. In the Actionscript section, click the "Custom" button. For the Action type,
check the "Change" checkbox. In the code section, enter:
function ff_number1_action(element, action) { ff_getElementByName('total').value = Number(ff_getElementByName('number1').value) + Number(ff_getElementByName('number2').value); } // ff_number1_action
Now click on the "Save Properties" button at the bottom of the page to save the element.
NOTE: the ‘name’ shown in red in the example below should be the same in all instances. So if you name
your element Product1 instead of number1, then the code should be:
function ff_Product1_action(element, action)
{
ff_getElementByName('total').value =
Number(ff_getElementByName('Product1').value) +
Number(ff_getElementByName('number2').value);
}
// ff_Product1_action
(That text would need to be changed in ALL instances of the code for each element.) - Create a second element where a single price will be entered or selected (textfield and/or select-list
allowing a choice of one option only) with properties as follows:
Label: Second Price
Name: number2
Go to the Advanced tab of the element. In the Actionscript section, click the "Custom" button. For the Action type,
check the "Change" checkbox. In the code section, enter:
function ff_number2_action(element, action) { ff_getElementByName('total').value = Number(ff_getElementByName('number1').value) + Number(ff_getElementByName('number2').value); } // ff_number2_action
Now click on the "Save Properties" button at the bottom of the page to save the element.
- Create a textfield element as follows:
Label: Total
Name: total
Go to the Advanced tab of the element. Put a checkmark in the "Readonly" checkbox. (That way, a user can’t
change the total amount calculated.) In the Actionscript section, click the "Custom" button. For the Action type,
NONE of the boxes should be checked. In the code section, enter:
function ff_total_action(element,action) { ff_getElementByName('total').value = 0; { ff_getElementByName('total').value = Number(ff_getElementByName('number1').value) + Number(ff_getElementByName('number2').value); } } // ff_total_action
in the upper right-hand corner of the screen to save the form itself.
Click on the "Save Properties" button at the bottom of the page to save the element. Then click on the SAVE icon
The code for Subtraction Multiplication and Division is pretty the same. All you need to do is to replace the operand " + " with " - " , " * " or " / "