In this example we will insert the $ symbol in front of the figure resulting from different calculations with other elements.
Having two elements of type list selection and a text element that displays the result of the sum of the values of both lists, making a normal calculation the value is displayed, but not the euro symbol (or dollar). So having two selection lists:
- List 1 (name list1):
0; Product A;250
0;Product B;290
0;Product C;320
- List 2 (name list2):
0; Extra A;35
0;Extra B;49
0;Extra C;70
- Text element which show the final result with name 'result'.
Thus, in each of the selection lists > Advanced, we will create both custom action scripts to trigger the calculation. For example, the code for the first list looks like:
function ff_list1_action(element,action) { switch (action) { case 'change': ff_getElementByName('result').value = 0; ff_getElementByName('result').value = (Number(ff_getElementByName('list1').value) + Number(ff_getElementByName('list2').value)); break; default:; } // switch } //function ff_list1_action}
To add the $ symbol at the beginning of the number to be displayed in the result element, we vary slightly the above code:
function ff_list1_action(element,action) { switch (action) { case 'change': ff_getElementByName('result').value = 0; ff_getElementByName('result').value = '$' + (Number(ff_getElementByName('list1').value) + Number(ff_getElementByName('list2').value)); break; default:; } // switch } //function ff_lista1_action