How can I add multiple single choice and show the total in a textbox?
Hello @Roie,
You can calculate the sum using the code. This is the code example for two single choice fields:
function calculateSum() {
//check if the value is selected for all fields
if (fd.field('Choice1').value && fd.field('Choice2').value) {
fd.field('Total').value = Number(fd.field('Choice1').value) + Number(fd.field('Choice2').value)
}
//if any field is blank the total is set to 0
else {
fd.field('Total').value = 0;
}
}
// Calling function when field value changes
fd.field('Choice1').$on('change', calculateSum);
fd.field('Choice2').$on('change', calculateSum);
// Calling function on form loading
calculateSum();