View Full Version : Order script with calculations?
Elmore
12-09-2002, 12:34 PM
Hi!
Is it possible to make an ordering page that has
different products that would be then calculated and
sent to formmail.pl and that there are special prices like
"buy 10 and pay for 9" (the cheapest product would be the free one) in javascript?
Or are there better options for achieving this?
Thanks!
piglet
12-09-2002, 12:50 PM
Hi,
Yes - sure you can do this sort of thing with javascript. Just be sure that any calculations you do using Javascript you redo on the server side and compare the results.
It's very easy for someone to fool about with the scripting and supply the wrong numbers to you. The only use for this sort of thing in Javascript is to aviod having to make the user submit a form and then wait for a response back from the server.
Do you have an example of exactly what you want to do? We can talk you through how to do the JS side of it then.
Elmore
12-09-2002, 01:19 PM
Fast response i got :) thanks!
Firstly i must say that i'm not very experienced with javascript (most of have been pop-ups that i've done) i was looking around to different shopping carts etc. but due necessity i thought to do it javascript way.
The thing i'd like to be able to do would be that:
If you buy 4 you pay for 3,
if you buy 6 you pay for 4 and
if you buy 8 you pay for 6.
And those free ones are always the same price (400).
So i thought that the code would be kind of like:
normal calculations first and if there are 4 checkboxes then -400 and if there are 6 then -800 etc.
Then there would need to be a way to send that calculation with the rest of the order (customer details) to formmail.pl that would forward it via e-mail.
Thanks!
About safety... it is possible to play with the code... but the one that would be the one messing with the code would be the customer, right? so then the guilty one would be there to blame :) (or was there something i didn't understand :))
piglet
12-09-2002, 01:45 PM
Hi,
You're probably better off doing a kind of multiplier sort of thing:
<html><body>
<form method="post" action="">
Qty: <input type="text" name="Number" onchange="this.value=Math.floor(this.value*1);calc(this);"/>
Unit Price: <input type="text" name="Cost" value="10" />
Total: <input type="text" name="Total" onfocus="this.blur()" value="0" />
</form>
<script type="text/javascript">
function calc(x){
var num = x.value;
var mult = 0;
if (num>=8) mult=6
else if (num>=6) mult=4
else if (num>=4) mult=3
else mult=num;
x.form.Total.value=(x.form.Cost.value*1)*mult
}
//-->
</script></body></html>
Elmore
12-09-2002, 02:36 PM
Thanks!
That got me started :)
Here's to whole thing i'm after
* ordering form *
Product Price order
Prod A 400 X (checkbox)
Prod B 400 X
Prod C 800 X
etc.
Total=
Name:
Address:
(clear) (submit order button)
(submit button goes to formmail)
Now i'm going to bang my head on the wall :) and try to make that. Crash course to javascript!
Thanks again!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.