Adding up form results

User 1744013 Photo


Registered User
89 posts

I'm woking on creating a questionnaire with yes - no answers. Does anyone know how I could add up the results and have them sent with the email notification?
Thanks
James Rook
User 187934 Photo


Senior Advisor
20,193 posts

CC wants to add calculations in the future but one way around it for now would be to have a number show with conditionals.:)
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 1744013 Photo


Registered User
89 posts

Ok, thanks. I'll have to look into conditionals since I've not worked with them before. This isn't a big deal - just something I thought might be useful for my client.
James Rook
User 1744013 Photo


Registered User
89 posts

I did find this script:
<script type="text/javascript">var inputTags = document.getElementsByTagName('input');
var checkboxCount = 0;
for (var i=0, length = inputTags.length; i<length; i++) {
if (inputTags[i].type == 'checkbox') {
checkboxCount++;
}
}
alert(checkboxCount);
</script></script>

Which sort of does what I want but it displays a count when the page loads, not after the boxes are checked. I imagine I need to add something like alert on submit but I don't know any java coding at this time.
James Rook
User 187934 Photo


Senior Advisor
20,193 posts

This works. Paste into an HTML element.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script type="text/javascript">$(document).ready(function () {
$("input[type=checkbox]").each(function () {
$(this).change(updateCount);
});
updateCount();
function updateCount () {
var count = $("input[type=checkbox]:checked").size();
$("#count").text(count);
$("#status").toggle(count > 0);
};
});</script>
<div id="status">
<p id="count">
0
</p>
</div>
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 1744013 Photo


Registered User
89 posts

Thanks - it's almost what I need. Is there any way to count the yes and no answers seperately? In other words the user checked say 4 questions yes and 6 questions no?
James Rook
User 187934 Photo


Senior Advisor
20,193 posts

This is where it gets tricky. Are you willing to alter the form html?
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 38401 Photo


Senior Advisor
10,951 posts

Well... you "could" do it with conditionals, but depending on how many questions there are (and I'm imagining a lot of you are needing the program to tally for you), there would require a ton of hidden fields for each possible combination. Would probably be a whole lot easier to edit the html lol.

User 187934 Photo


Senior Advisor
20,193 posts

@Jo
Eric Rohloff wrote:
CC wants to add calculations in the future but one way around it for now would be to have a number show with conditionals.:)
:rolleyes:
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 1744013 Photo


Registered User
89 posts

I've no problem with altering the form HTML. Any ideas are appreciated.
I'm probably not the only one that wishes calculations were aready a feature. It would be very useful for surveys and the like. What I'm doing is a questionnaire with about 20 questions, all yes or no. If the script could count how many yes's and then how many no's and include it with the form results that are emailed to the form owner it would be great. Even better would be if along with the yes/no totals certain questions could be flagged to trigger some type of special notice. For example: If someone answered yes to question 5, the results would include a notice or something. This is for a mental health questionnaire so a few of the answers might be very important for the Dr to be aware of quickly.
James Rook

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.