I am looking for a simple script for an ordering form that multiplies price by number of items and then sums up the total prices. thanks..
I am looking for a simple script for an ordering form that multiplies price by number of items and then sums up the total prices. thanks..
This can be done a number of ways. Can you please be more specific to what your needs are, possible post some code or a link to an example of what you have?
Corrections to my coding/thoughts welcome.
Product Unit Price Qty Total Price
Product 1 $3.29 4 $13.16
Product 2 $4.10 7 $28.70
Product 3 $1.98 1 $1.98
Product 4 $5.75 3 $17.25
Product 5 $3.89 10 $38.90
Total Order $99.99
Okay that doesn't really tell me anything but I'll just assume some things. This may no function exactly but is an example.
I've done this in javascript because that is the forum you posted this in. You probably want to process a request like this in php or some other server language though.Code:<script type="type/javascript"> var product1_q = document.getElementById("product1_quantity").value; //assuming this is an input with type text for quantity wanted this could also error if they enter text should check that as well var product1_p = document.getElementById("product1_price").value; //assuming this is input type hidden with the price as 12.30 no $ or other characters product1_total = product1_p * product1_q; var current_total = product1_total; var product2_q = document.getElementById("product2_quantity").value; //assuming this is an input with type text for quantity wanted this could also error if they enter text should check that as well var product2_p = document.getElementById("product2_price").value; //assuming this is input type hidden with the price as 12.30 no $ or other characters product2_total = product2_p * product2_q; current_total = current_total + product2_total; products_total = product2_q + product1_q; </script>
Corrections to my coding/thoughts welcome.
Does Javascript work in an email?
Nope.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Can HTML be used to perform the same calculations? or is there some other language available that can perform these calculations in an email?
No. You can perform them before you send the email, preferably on the server side as part of the email process.
That's what happens when you order something online and get a receipt email. The server calculates things up, if it hasn't already, and composes an email to the address you supplied.
An alternative would be to create a page just for the person and send them the address in an email. But once again, the server should be involved with this if it has any chance of being secure.
If what you're proposing is some sort of e-commerce, you really need an ssl (https server) or a third party service like PayPal to do things securely.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Bookmarks