Multiplying fields and then adding the results

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zacthespack
Forum Newbie
Posts: 16
Joined: Mon Oct 11, 2010 9:08 am

Multiplying fields and then adding the results

Post by zacthespack »

I am setting up a order form on my website http://www.acehireltd.co.uk/orderform/ , I have been able to pretty much set everything up including auto complete and adding space for another product when you check a box etc. However there is one last thing I need to do which I just cant work out.
Each product has a price that gets auto filled from a mysql datebase when the user enters the products name or code, the user must the enter a quantity of how many of that product they want. I need the price and quantity field to be multiplied together an the result of this displayed in another field on the form (e.g called total product price).
I also then at the bottom of the form need a complete total price to be worked out by adding all the total product prices as well as the delivery cost field.
I hope someone can help.
Thanks you.
phphelpme
Forum Contributor
Posts: 261
Joined: Sun Nov 21, 2010 3:32 pm

Re: Multiplying fields and then adding the results

Post by phphelpme »

I suggest you look into Java code to handle this for you if you need this calculation done while they are still on the form. Most people I have noticed just get the page to refresh on submit etc so they can use php to perform the calculation based upon the POST values.

You could always add a refresh button but tell it to submit the values to your form again and get your php code to calculate the values for you. That way you steer clear of java code and remain using php.

Or you could display a summary page confirming everything they have chosen which would then display the total values but if you are really after the form fields to be populated while they are adding products then use java code for it.

Best wishes
Post Reply