SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: adding things up
Hybrid View
-
Dec 6, 2007, 09:31 #1
adding things up
Hi Everyone
I have this code:
Code:<script language="JavaScript"> var one=0; var two=0; function myCalc() { one=Math.abs(parseFloat(document.FORM.one.value)); two=Math.abs(parseFloat(document.FORM.two.value)); document.FORM.two.value=(one*12.99); } </script>
I need to have it so if the number is more than 1 in 'one' it add's 12.99 and then and only adds 6.50 for every other number more than 1.
Basically what I want it to do is work out a figure if you buy 1 you get the others at half price.
Is this doable with this script?
Many thanks
-
Dec 6, 2007, 10:05 #2
- Join Date
- Apr 2006
- Location
- Maryland
- Posts
- 1,838
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hmm. Are you using any server-side language for this? I wouldn't rely on Javascript for this (since it can be disabled).
-
Dec 6, 2007, 10:35 #3
Hi,
Thanks for getting back to me.
I'm using Coldfusion with it.
Regards
-
Dec 7, 2007, 11:50 #4
- Join Date
- May 2005
- Posts
- 12
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Code:var two = (one > 0) ? (12.99 + ((one-1) * 6.99)) : 0;
If one is more than 1, you'll get one at 12.99 and the rest at 6.99
If one is 0 or less (or not a number) then you'll get 0
Also you might want to use parseInt() instead of parseFloat(). ParseInt will convert decimal numbers (10.25, for example) to integers (10). You probably won't selling .25 of something.
--dave
-
Dec 9, 2007, 14:29 #5
Hi Dave,
Thanks you very much for this!
Bookmarks