I have a form in CF7 that I would like to assign a numerical value to the Value of each radio choice, then calculate (add) the values of each choice and display a result based on the total.
I have the form structure in place, but need help in calculating the value of the Values, and displaying the result.
Here is a simple structure to explain -
Question 1: Choice A, B, C (A=1, B=2, C=3)
Question 2: Choice A, B, C (A=1, B=2, C=3)
Question 3: Choice A, B, C (A=1, B=2, C=3)
Question 4: Choice A, B, C (A=1, B=2, C=3)
Question 5: Choice A, B, C (A=1, B=2, C=3)
Now a definition has already been set which would mean:
1-7 = Not so good
7-14 = Good
14+ = Excellent
If I select say:
B, C, B, A, B, from Question 1 - 5 respectively, then a score of 10 (2+3+2+1+2) will be calculated and the definition "Good' Will be displayed.
Thank you for any help.
I found this post which is similar, but am not sure if it can work.
var calc = function() {
var no = $('#no').val();
var g1 = $('input[name="g1"]:checked').val();
var g2 = $('input[name="g2"]:checked').val();
var simple = no * 10;
$('#simple').val(simple.toFixed());
var complex = (no * g1 * 30) + (no * g2 * 100);
$('#complex').val(complex.toFixed());
}
$('#no, input[name="g1"], input[name="g2"]').on('change', function() {
calc();
});
<form id="form45" action="" class="">
<ul>
<li>
<input type="radio" name="radio-q1" value="Water">
<span>Water</span>
</li>
<li>
<input type="radio" name="radio-q1" value="Sportsdrink">
<span>Sportsdrink</span>
</li>
<li>
<input type="radio" name="radio-q1" value="Milk">
<span>Milk</span>
</li>
</ul>
<div>
<button type="submit" class="btn red"><i aria-hidden="true"></i> Calculate Risk</button>
</div>
<input type="hidden" name="source" value="">
</form>