Calculate totals in Web Form Builder?...

User 1982097 Photo


Registered User
72 posts

it looks like I could create hidden fields in the form options..not sure if it helps
Coffee roasting is my passion - seriously
User 187934 Photo


Senior Advisor
20,181 posts

There's several ways to accomplish this. You could add hidden inputs to the form by using an html element but that may get a little clunky.
I think this will get you what you need. You will have to add the rest of the price options as I only did the first two as an example. You'll also need a Price total input to show your running total. I named mine Total_Items_Price.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script>var jQ = $.noConflict(true);
// version 2
jQ( document ).ready(function() {
// Set Total_Items_Entered and Total_Items_Price to read only
jQ('input[name="Total_Items_Entered"]').prop('readonly', true);
jQ('input[name="Total_Items_Price"]').prop('readonly', true);
// add the class sum to all inputs that we want to add
jQ('input[name^="GB"]').addClass( "sum" );
// This is where the price will be set for each input
// Add the data attribute to hold the price add one for each input
jQ('input[name="GB-HarmonyDecaf-ground"]').data('price',20.25);
jQ('input[name="GB-SunriseBreakfast-ground"]').data('price',25.95);

// on keyup check that the value isn't blank and it's numeric
jQ('input[name^="GB"]').on('keyup', function() {

if (jQ(this).val()!="" || jQ.isNumeric(jQ(this).val())){

// if input value is good fire the function
calc_dues();
}
});

// This is the calculate function
function calc_dues() {

var sum = 0;
var sum_price = 0;
jQ('.sum').each(function(){
if(jQ.isNumeric(this.value)){
sum += parseFloat(this.value);
sum_price += parseFloat(this.value) * parseFloat(jQ(this).data('price'));
jQ('input[name="Total_Items_Entered"]').val(sum);
jQ('input[name="Total_Items_Price"]').val(sum_price.toFixed(2));
}
});

}
});</script>

And yes I like coffee.
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 1982097 Photo


Registered User
72 posts

awesome - thanks so much
Coffee roasting is my passion - seriously
User 1982097 Photo


Registered User
72 posts

Eric,
You've been a huge help. Once again thanks. Love my new form.
Question: I used to use the flash ver of the form builder which produced very lightweight files that I could easily export to my server. When I export a form from the new formbuilder, it is around 20 mb with all files. A. Are all the files necessary for a working form? B.) I make sometimes 5 of the same form with different settings a day and upload them. Any suggestions as so how to make this simpler?
Or, if I pointed a programmer to my form/files would you expect he could somehow automate the form creation/replcation with new settings somehow. I know this seems weird.
The driver is I could have many people hitting the same form and i prefer not to make them have to log in to get to it, hence I have not built this into a system. Thx
Coffee roasting is my passion - seriously
User 187934 Photo


Senior Advisor
20,181 posts

One thing would be to write your own formname.php to process the data. This would remove the need for several files but would also require somebody with knowledge of php.
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 1982097 Photo


Registered User
72 posts

Eric,
Is there a way to make the Total_Items_Price below included in the submission of the form data to the database?
It doesn't currently.
much thanks

Eric Rohloff wrote:
There's several ways to accomplish this. You could add hidden inputs to the form by using an html element but that may get a little clunky.
I think this will get you what you need. You will have to add the rest of the price options as I only did the first two as an example. You'll also need a Price total input to show your running total. I named mine Total_Items_Price.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script>var jQ = $.noConflict(true);
// version 2
jQ( document ).ready(function() {
// Set Total_Items_Entered and Total_Items_Price to read only
jQ('input[name="Total_Items_Entered"]').prop('readonly', true);
jQ('input[name="Total_Items_Price"]').prop('readonly', true);
// add the class sum to all inputs that we want to add
jQ('input[name^="GB"]').addClass( "sum" );
// This is where the price will be set for each input
// Add the data attribute to hold the price add one for each input
jQ('input[name="GB-HarmonyDecaf-ground"]').data('price',20.25);
jQ('input[name="GB-SunriseBreakfast-ground"]').data('price',25.95);

// on keyup check that the value isn't blank and it's numeric
jQ('input[name^="GB"]').on('keyup', function() {

if (jQ(this).val()!="" || jQ.isNumeric(jQ(this).val())){

// if input value is good fire the function
calc_dues();
}
});

// This is the calculate function
function calc_dues() {

var sum = 0;
var sum_price = 0;
jQ('.sum').each(function(){
if(jQ.isNumeric(this.value)){
sum += parseFloat(this.value);
sum_price += parseFloat(this.value) * parseFloat(jQ(this).data('price'));
jQ('input[name="Total_Items_Entered"]').val(sum);
jQ('input[name="Total_Items_Price"]').val(sum_price.toFixed(2));
}
});

}
});</script>

And yes I like coffee.
Coffee roasting is my passion - seriously
User 187934 Photo


Senior Advisor
20,181 posts

The code is already setup to do that. It's placing the total in an input on your form that's been set to readonly with the script so it will get submitted.
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 1982097 Photo


Registered User
72 posts

hmm, I must have a mistake or something. Will check. Hasn't been working
Coffee roasting is my passion - seriously
User 1982097 Photo


Registered User
72 posts

I don't see why it isn't working.
http://givingbean.com/ez/0503webformwit … ithGB.html
Coffee roasting is my passion - seriously
User 187934 Photo


Senior Advisor
20,181 posts

Your total of items and total value inputs are disabled. Did you add the disabled attribute to them after export?
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

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.