Custom form: calculate input fields

(Jennifer Weiley) #1

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.

[Matrix Version]

(Luke Wright) #2

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.

(Nick Papadatos) #3

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?

(Jane Butler) #4

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

(Nick Papadatos) #5

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:

       var val1 =+$("#q1254186_q1").val();
       var val2 =+$("#q1254186_q2").val();

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


(Jennifer Weiley) #6

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