• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 8. The JavaScript Shopping Cart > Step 4: Adding Products to the Shoppi...

8.7. Step 4: Adding Products to the Shopping Bag

Putting things in the shopping bag is easy. Users need only click the affectionately titled link "Gimme One." This calls the correspondingly named function gimmeOne(). Lines 112-133 have the details:

function gimmeOne() {
  if (!gimmeControl) {
     alert("Nothing on this screen to give you.");
    return;
    }
  for (var i = 0; i < shoppingBag.things.length; i++) {
     if (categorySet[curCLoc].prodLine[curPLoc].plu ==
       shoppingBag.things[i].plu) {
      alert("That's already in your bag. You can change the quantity " +
         "by choosing View/Change Bag.");
      return;
      }
     }
  shoppingBag.things[shoppingBag.things.length] =
     categorySet[curCLoc].prodLine[curPLoc];
  shoppingBag.things[shoppingBag.things.length - 1].itemQty = 1;
  shoppingBag.things[shoppingBag.things.length - 1].category =
     categorySet[curCLoc].name;
  alert("OK. You put the " +
     shoppingBag.things[shoppingBag.things.length - 1].name +
     " in your bag.");
  }

				

					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint