Link to home
Start Free TrialLog in
Avatar of Jessee
JesseeFlag for Australia

asked on

Javascript for each certain amount, increase variable

Hi there,

I am needing to calculate shipping in a website I am writing. Each item we sell has a maxshipping variable which shows how many of that item can be shipped before the items shipping cost is increased.

E.g.
An item has a shipping cost of $0.60 for up to 10 of the items... After that 10 I want to increase it by another $0.60... then so forth for each 10 items.

How do I go about doing this?

Thanks,
Jessee
Avatar of Insoftservice inso
Insoftservice inso
Flag of India image

so you mean to say for 10 items its $0.60
now if it have only one item it would be also $0.60 right ?
please confirm.

If yes please copy below code and save it as "test.html".

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
 <head>
  <title>love to marry </title>
  <meta name="Generator" content="Lorem ipsum dolor sit amet,">
  <meta name="Author" content=" consectetur.adipisicing,">
  <meta name="Keywords" content="sed do eiusmod tempor incididunt">
  <meta name="Description" content="ut labore et dolore magna aliqua.">
  <script type="text/javascript">

  function bridedress()
  {
      var item_no =25;
      var cost = 0.60;
      var quantity =10;
      var extra = 0;
      var item = 0;
      var totalprice =0 ;
      var extraitem =0 ;

      extraitem = (item_no%quantity);
      item = Math.floor(item_no/quantity);
      if(extraitem < quantity)
      {
         extra = 1;// to keep additional item less than 10 as 1 unit or quantity
      }
      totalprice = (item*cost)+(extra*cost);
      alert(totalprice)
      alert(item)
      alert(extra*cost)


  }

  </script>
 </head>

 <body>
  <a href="javascript:bridedress()">lovetomarry</a>
 </body>
</html>

(Edit: Possible advertising removed - Modulus_Twelve)
Avatar of Jessee

ASKER

Hi there,

Yes.
1 - 10 items = 0.60
11 - 20 items = 1.20 etc etc...

Will try this code and get back to you.

Thanks,
Jessee
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jessee

ASKER

Hey there,

The maxshipping changes with each item. Sometimes only 2 items can be sent for 0.60... other times 10 items can be. How do I include that?

Thanks,
Jessee
Did you try it?  If you add 1 through 10 in the qty box, it will be 60 cents. If you use 11 through 20 it will be 1.20.
Avatar of Jessee

ASKER

Works like a charm. Just needed to put the maxshipping in where the /10 was.

Thank you!
Hi @Letsgetcoding
For 25 it has to 1.80 right?