Calculations based on form input

User 315488 Photo


Registered User
90 posts

I have a form here:
http://upc.utah.gov/evals/evalFormTest.html

It's a work in progress, but what I would like to do is to somehow calculate education credit based on the responses on the form when it is submitted. Then I would like to popup a form showing the name, bar # and the calculated credit on another form or perhaps another page. There is a certain amount of credit for each topic that is being scored. The user must select a score for each topic or they get 0 credit. The calc function (however it's done) would need to look at each numbered topic and if scored, assign a credit for that topic (ranges from 0 to 3 with 0.25 and 0.5 and 1.5 being valid values). It would keep track of the total score by adding the value of each topic to the previous total. I do this easily in C# code in a desktop application, but don't know how to implement the same type of calc with form input.

I thought about putting together a custom confirmation page / message, but I don't know how to: 1. Calculate the values I need; 2. Put those values on the confirmation form.

I'm OK with doing coding, but I'm just starting to learn php and jquery so would need some general guidance on what is needed (if necessary).

Is this too much for WFB to help with or would I be better off doing this in a completely different way?

Thanks for any help,

Ron
User 187934 Photo


Senior Advisor
20,271 posts

Add a html element to your form and paste the code below into it.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
function calcscore(){
var score = 0;
$("input[type='radio']:checked").each(function(){
var value = $(this).val();
if(value >0){
score+=parseInt($(this).val(),10);
}
});
$("input[name=sum]").val(score)
}
$().ready(function(){
$("input[type=radio]").change(function(){
calcscore()
});
});
</script>

Now add a number input to your form and name it sum.
Here's my quick version. Sum total at the bottom.
http://ericrohloff.com/coffeecup/ccforu … erRon.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 315488 Photo


Registered User
90 posts

This is great and it works as expected.
The problem is that the calc is a bit more complicated. I didn't explain it well.

It doesn't matter what the value of the radio buttons are (Presentation / Material), only that they are checked. If not checked (rather, if something other than N/A is not checked), then the value = 0; otherwise the value will be either 0.25; 0.5; 0.75; 1; 1.25; 1.5; 1.75; or 2 depending on the topic. Example: The 1st topic (1. Introduction of Scenario) will have a education credit value of 0.5. The 2nd one will have a credit value of 1.0, the 3rd one is 1.5; the 4th one is 1.0, etc.

I've tried adding a hidden number field that has the actual value to count, but it won't let me put a read-only value in it. I can put a text field on each topic and hide it and make it read only. I guess I don't have to hide it if it's a problem.
Is there some way to sum the values in the text box (under each topic) to put in the sum input field?
I think I can use the parseFloat() function to return a value from the text box, but I'm not sure how to get the value from all the text fields that have a valid option selected.

To make it more complicated, I only look at the Presentation scores to be > 0 in order to add the education credit. It doesn't matter (for the credit) if the Materials option is checked or not.

You gave me more than I expected already and showed me some things that are possible and I appreciate that. I'm not really trying to get you to do the coding for me, but I'm lost as to how to proceed or even if this is possible.

Here is the pseudo code of what I want to do:
Check topic 1
If Presentation score value selected > 0
sum += val(cle1)
else
sum += 0
Check topic 2
If Presentation score value selected > 0
sum += val(cle2)
else
sum += 0
etc.....

Is this too much of a stretch or can jquery handle this?
I've uploaded a new form with the text boxes with their cle (continuing legal education) values added.
Thanks...
User 187934 Photo


Senior Advisor
20,271 posts

Do you need those inputs cel1 & cel2 etc. to actually be showing or even in use with the form?
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 315488 Photo


Registered User
90 posts

Eric Rohloff wrote:
Do you need those inputs cel1 & cel2 etc. to actually be showing or even in use with the form?


Not really - I just put them there for reference and to illustrate the values I'm actually trying to use to get the final sum. I would prefer that they show or even be there. I wondered if I could just create a series of variables to hold those values and use them in the calculation.
I've toyed with the idea of doing a web application using c# winforms or something similar, but that's quite a bit of work to just get input like this.
User 187934 Photo


Senior Advisor
20,271 posts

How does this look.
http://ericrohloff.com/coffeecup/ccforu … rRon2.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 315488 Photo


Registered User
90 posts

That looks about how I did it.
I just realized that I said I would prefer that they show. I meant I would prefer that they NOT show.
Will this work if the fields are hidden?

Thanks,
User 187934 Photo


Senior Advisor
20,271 posts

Yes, my scripts do not depend on whether any inputs are hidden or showing. It can be changed to work with straight variables instead.
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 2590668 Photo


Registered User
40 posts

It sure IS complicated to add up numbers and values on the form. I'm not going there either to figure it out. In fact, without a simple to use feature like this the WFB is almost useless. What is a purchase order without a calculation?
James Kershaw |Reminiscence Facilitator
jim@momentostudio.info | http://ca.linkedin.com/in/reminiscence
289-501-4026 | www.momentostudio.info


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.