PDA

View Full Version : Looking for a form script that performs simple arithmetic functions



techsol
10-02-2010, 03:01 PM
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..

bluewalrus
10-02-2010, 03:07 PM
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?

techsol
10-02-2010, 03:33 PM
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

bluewalrus
10-02-2010, 03:45 PM
Okay that doesn't really tell me anything but I'll just assume some things. This may no function exactly but is an example.



<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>


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.

techsol
10-02-2010, 04:44 PM
Does Javascript work in an email?

jscheuer1
10-02-2010, 05:20 PM
Nope.

techsol
10-02-2010, 05:28 PM
Can HTML be used to perform the same calculations? or is there some other language available that can perform these calculations in an email?

jscheuer1
10-02-2010, 06:48 PM
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.