SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict AshleyH's Avatar
    Join Date
    Mar 2005
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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>
    which simply multiplies 'one' by 12.99.

    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

  2. #2
    Guru in training bronze trophy SoulScratch's Avatar
    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).

  3. #3
    SitePoint Addict AshleyH's Avatar
    Join Date
    Mar 2005
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks for getting back to me.

    I'm using Coldfusion with it.

    Regards

  4. #4
    SitePoint Member
    Join Date
    May 2005
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AshleyH View Post

    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.
    Code:
    var two = (one > 0) ? (12.99 + ((one-1) * 6.99)) : 0;
    If one is 1, then you'll get 12.99
    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

  5. #5
    SitePoint Addict AshleyH's Avatar
    Join Date
    Mar 2005
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Dave,

    Thanks you very much for this!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •