Custom form: calculate input fields

I am about to build a custom form and wondering whether it’s possible to configure a calculation based on input fields.

I will be asking users to enter numbers in fields A, B, C and D and then field E is the sum of the 4 fields. I haven’t spotted this in the manual yet but wondering if anyone has done it.

https://matrix.squiz.net/manuals/custom-form

[Matrix Version 5.4.0.1]

Hi Jennifer,

It’s not something that doesn’t come standard in Matrix, no. It’s likely that it could be possible with a bit of JavaScript implementation, but it’s not something that’s inside Matrix itself from memory.

1 Like

Hi Jennifer

You can do it via javascript - if you have a look at this video it shows you how if that works for you?

Just check if using javascript that the sum goes into the question field. We used similar on a form - looked great added up but when the form was submitted the fields were empty

1 Like

Correct - When you say fields were empty do you mean in the Receipt Email Options?
Obviously you’ll need to properly reference your input ID’s in your javascript.
Not sophisticated but just of the top of my head something like:

    $(function(){	  
	    $(".calc").keyup(function(){
       var val1 =+$("#q1254186_q1").val();
       var val2 =+$("#q1254186_q2").val();
       $("#q1254186_q3").val(val1+val2);
     });

Yo can hide the result (total) but show when all fields have a value?
Add your own class name (example .calc) in the details screen of your input field

Cheers
N

1 Like

Thanks @NickyP, @jbutler and @Luke_Wright. I’ll take a look at the javascript. (Well, I’ll get someone who understands javascript to look at it!)