Unfortunately, the username and password you have entered do not match!

Registration

Unfortunately, this username is already taken!

Unfortunately, this e-mail address is already used!

Please retype the verification code.

All fields are required

RSForm!Pro - How to perform radio group calculations

How to perform radio group calculations

In this article we will describe how to make a simple calculation with values from a radio group. Let suppose, for example, that we have the following components:

1. Radio group:

Name: radio1

Caption: radio1

Items: 1|Description1

2|Description2

3|Description3


2. Radio group:

Name: radio2

Caption: radio2

Items: 1|Description1

2|Description2

3|Description3


3. Hidden field

Name: result

Default Value: 0


4. Submit Button:

Name: submit

Label: submit

Additional Attributes: onclick="calculate();"


In the "Form Layout" tab, uncheck the "Auto Generate Layout" checkbox and paste the following Javascript code at the begging of the existing layout code:

function calculate()

{

var op1=document.getElementsByName('form[radio1]');

var op2=document.getElementsByName('form[radio2]');

var result=document.getElementById('result');

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);

alert(result.value);

return false;

}

In order to display the result of this calculation just the placeholder for the hidden field, in this case: {result:value}. This can be used in "Thank you" page as well as in any email configuration.

Feedback