Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Count answered Q's and show count

Hi there (again!).. Within my survey I have 5 sections. At the end of the survey I want to display to the respondent the number of sections they have completed. I can base this on the final question of each section. I thought that I could create a field (i.e. "Totals") and create this by adding together the "answered" count on each of the five questions. Is this possible?
asked Feb 16, 2017 by Christine Hanley (370 points)

1 Answer

+2 votes
This code will display the number of Q1, Q2, and Q3 that have been answered:

<span id="totalAnswered"></span>

<script>
$(document).ready(function(){
    var totalAnswered = 0;
    totalAnswered += [% Answered(Q1) %];
    totalAnswered += [% Answered(Q2) %];
    totalAnswered += [% Answered(Q3) %];
    $('#totalAnswered').text(totalAnswered);
})
</script>
answered Feb 16, 2017 by Zachary Platinum Sawtooth Software, Inc. (91,500 points)
Thanks Zachary. I received error: "The value of the property '$' is null or undefined, not a Function object." Am I missing a step?
v7, I assume?  Here's a pure JavaScript solution for you:

<span id="totalAnswered"></span>

<script>
var totalAnswered = 0;
totalAnswered += [% Answered(Q1) %];
totalAnswered += [% Answered(Q2) %];
totalAnswered += [% Answered(Q3) %];
document.getElementById("totalAnswered").textContent = totalAnswered;
</script>
...