This article will present how to create calculations in RSForm! Pro with textboxes, radio buttons and select lists.
- In order to create calculations with textboxes you will have to use the following script in the "CSS and Javascript" > Javscript section:
function calculateText(){
var op1=document.getElementById('field1');
var op2=document.getElementById('field2');
var result=document.getElementById('Total');
if(op1.value=="" || op1.value!=parseFloat(op1.value)) op1.value=0;
if(op2.value=="" || op2.value!=parseFloat(op2.value)) op2.value=0;
result.value=0;
result.value=parseInt(result.value);
result.value=parseInt(result.value)+parseInt(op1.value)+parseInt(op2.value);}In the above script you will have to change the values "field1", "field2" and "Total" with the name of your fields from the form. Also you will have to place the trigger for the function in the Additional Attributes section of a button:
onclick="calculateText();"
- The calculations with radio buttons are made with the help of the following script, which is also placed in the "CSS and Javascript" > Javscript section:
function calculateRadio(){
var op1=document.getElementsByName('form[radio1]');
var op2=document.getElementsByName('form[radio2]');
var result=document.getElementById('Total2');
result.value=0;
result.value=parseInt(result.value);
for(i=0;i<op1.length;i++)
if(op1[i].checked) result.value=parseInt(result.value)+parseInt(op1[i].value);
for(i=0;i<op2.length;i++)
if(op2[i].checked) result.value=parseInt(result.value)+parseInt(op2[i].value);}You will have to change the values "radio1", "radio2" and "Total2" with the name of your radio button fields and textbox field(in which the total is displayed). Also the trigger of the function will have to be placed in the Additional Attributes section of a button:
onclick="calculateRadio();"
- Similar with the radio button calculation function, the select list calculations are made with the following script:
function calculateList(){
var op1=document.getElementById('selectlist');
var result=document.getElementById('Total3');
result.value=0;
result.value=parseInt(result.value);
for(i=0;i<op1.length;i++)
if(op1.options[i].selected) result.value=parseInt(result.value)+parseInt(op1[i].value);}You will have to change the values "selectlist" and "Total3" in the above script with the values corresponding to the select list and textbox fields from your form. You will also have to place the trigger for the function in the Additional Attributes section of a button:
onclick="calculateList();"




