Sum if

How to conditionally sum form fields based on a radio button selection.

Overview

The issue was caused by incorrect JavaScript event handling and variable naming when trying to sum text fields only if a radio group was set to "yes".
Correct the event listener to trigger the calculation function properly and ensure the function checks the correct condition, such as verifying if a specific checkbox is checked, to perform the sum and multiplication.

Answered
ChronoForms v6
Sa Savadori 22 Oct, 2019
[font][/font]
Sorry, my English

I have been trying for weeks to make my form work without success

I have to sum up several text fields if Radios group is "yes"
Help!!!!



js
window .addEvent ( 'domready' , function () {

$ ( 'field_radios' ) .addEvent ( 'change' , checkYes);


op('#1').on('change', operazione);
op('#2').on('change', operazione);
op('#3').on('change', operazione);
op('#4').on('change', operazione);



function checkYes () {
if ($ ( 'field_radios17' ) .checked === "yes") {
function operazione ()
{
var 1= Number (op('#bambini').val());
var 2= Number (op('#adulti').val());
var 3= Number (op('#transfer').val());
op('#4').val((( 1+ 2) * 3).toFixed(2));

}
}
}

}

Sa Savadori 23 Oct, 2019
Answer
Resolved!

if (op( '#checkbox106' ) .prop("checked") === true) { 

var 1= Number (op('#1').val());
var 2= Number (op('#2').val());
var 3= Number (op('#3').val());
op('#4').val((( 1+ 2) * 3).toFixed(2));

}
This topic is locked and no more replies can be posted.