Adding up form results - Post ID 207420

User 187934 Photo


Senior Advisor
20,265 posts

Now you want it with the form results. You keep changing what you want and that makes it difficult but now it's easy.:) You'll have to use the conditionals because the html form element isn't submitted with the rest of the results.:)
I did come up with a working example but it won't get submitted so it's not what you wanted.
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

Eric Rohloff wrote:
@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:


Yeah I was agreeing with you :P

Can you share that .fb file Eric? I'd like to see how you set that up myself, because my complicated mind thinks it is horribly complicated to do, and apparently it's not?
User 1744013 Photo


Registered User
89 posts

Sorry, I guess I wasn't clear with this, Thanks for the help.
James Rook
User 187934 Photo


Senior Advisor
20,265 posts

I pasted this into an HTML element. It's looking at Values "Yes" and "No" on the checkboxes. You could tweak it for any input value. You can apply css to it for positioning count. I didn't for the example.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("input[value=Yes]").each(function () {
$(this).change(updateCountyes);
});
updateCountyes();
function updateCountyes () {
var countyes = $("input[value=Yes]:checked").size();
$("#countyes").text(countyes);
$("#statusyes").toggle(countyes > 0);
};
$("input[value=No]").each(function () {
$(this).change(updateCountno);
});
updateCountno();
function updateCountno () {
var countno = $("input[value=No]:checked").size();
$("#countno").text(countno);
$("#statusno").toggle(countno > 0);
};
});</script>
<div id="yes">Yes
<div id="statusyes">
<p id="countyes">
0
</p>
</div></div>
<div id="no">No
<div id="statusno">
<p id="countno">
0
</p>
</div></div>


Sure would be nice if you could have the HTML element be submittable.:cool:
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

Appreciated Eric, for some reason I was thinking you did that with conditionals, but that's quite slick what you got there thanks :)
User 187934 Photo


Senior Advisor
20,265 posts

Hold on.;) I found a way to make it submittable.:cool: Just cleaning it up a bit.:lol:
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 187934 Photo


Senior Advisor
20,265 posts

Finally got back to this.:lol: The Check boxes need their options to be Yes and No Paste the code below into a HTML element in your form. Add two number input elements to your form. Name the Yes one numberyes and the No one numberno. Now preview your form and either look at the source code or use Firebug addin for Firefox to look at the code for the Yes and No input numbers. My input numberyes had a div id="item11_number_1" and the Yes label had a div id="item11". Tweak the code below where you see these to match yours. Do the same for the numberno input. Mine was id="item12_number_1" and id="item12".
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("input[value=Yes]").each(function () {
$(this).change(updateCountyes);
});
updateCountyes();
function updateCountyes () {
var countyes = $("input[value=Yes]:checked").size();
$("input#item11_number_1").val(countyes);
$("label#item11").toggle(countyes > 0);
};
$("input[value=No]").each(function () {
$(this).change(updateCountno);
});
updateCountno();
function updateCountno () {
var countno = $("input[value=No]:checked").size();
$("input#item12_number_1").val(countno);
$("label#item12").toggle(countno > 0);
};
});</script>



Lets all say JQuery is cool.:cool:
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

Very cool - just what I needed. I really think this should go into the Tips and Tricks thread. It'll be very useful for a lot of forms.
Thank You!:lol:
James Rook
User 38401 Photo


Senior Advisor
10,951 posts

Nice Eric, thanks! I missed this post yesterday somehow, glad you posted Hazy so it got bumped again :)
User 2147646 Photo


Registered User
233 posts

Thanks Eric! That will come in usefull :)


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.