Forums

Getting a total amount from multiple input boxes

jrthor2 11 Apr, 2013
I have a form where I have a dropdown box with values of 1-4. I have another dropdown of values 1-10. The first dropdown is for for the number of golfers in the group. The cost for a golfer is $60 per golfer. The second dropdown is for non-golfers, and the cost is $21 per person. In my email to the user once they submit the form, i want to give a total dollar amount of what the person owes. So the first dropdown value multiplied by 61 and the second dropdown multiplied by 21 and add that together for a total.

Could someone help me with this?

Thanks,
Jason
jrthor2 12 Apr, 2013
Can anyone help me with this?

Thanks
GreyHead 18 Apr, 2013
Hi jrthor2,

There are two ways to do this and ideally you will do both.

The most important is that you do the calculation using PHP in a Custom Code action in the On Submit action of your form.

The cosmetic version is to use JavaScript to do the same thing in a Load JS action in the On Load event of your form; that will allow you to display the result to the user immediately they change the form settings.

The exact code will of course depend on the names and ids of your form inputs.

Bob
gabedaly 19 Apr, 2013
Here is some javascript that I use to sum (add only) all inputs with a class name of "pound" and place the total in an input field with an id of "totalamount". I'm sure you can customize this to fit your needs. Or you can do it with php in the on submit event...


function sum(){
var total = 0;        
var pounds = document.querySelectorAll('.pound');
        for(var i=0;i<pounds.length;i++){
var poundall = parseFloat(pounds[i].value) || 0;
          total = total + poundall;
        }
        var tot_id = document.getElementById('totalamount');
        tot_id.value = total.toFixed(2);
}
This topic is locked and no more replies can be posted.