make e-commerce basket, using cookie


/ Published in: jQuery
Save to your folder(s)

link to plugin http://projects.exvoto.org/jquery-extjsoncookie/


Copy this code and paste it in your HTML
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="js/jquery-1.4.1.min.js"></script>
  4. <script type="text/javascript" src="js/jquery.json-2.2.js"></script>
  5. <script type="text/javascript" src="js/jquery.extjasoncookie-0.2.js"></script>
  6. <script>
  7. function onl(){
  8. save2basket(1,1000,8);
  9. var getByid = getFromBasket(1);
  10. alert(getByid.price) // trace price
  11. alert(getByid.quantity) // trace q
  12.  
  13. save2basket(1,1200,3); //change quantity or price
  14.  
  15. }
  16.  
  17.  
  18. function getFromBasket(id){
  19. var id = 'id'+String(id);
  20. return jQuery.extendedjsoncookie("getCookieVariable",id, "options");
  21. }
  22.  
  23. function save2basket(id,Price,Quantity){
  24. var id = 'id'+String(id);
  25. var Price = String(Price);
  26. var Quantity = String(Quantity);
  27. jQuery.extendedjsoncookie("removeCookie",id);
  28.  
  29. var opt = {price : Price,quantity : Quantity};
  30. jQuery.extendedjsoncookie("setCookieVariable",id, "options", opt );
  31. }
  32.  
  33. function removeFromBasket(id){
  34. var id = 'id'+String(id);
  35. jQuery.extendedjsoncookie("removeCookie",id);
  36. }
  37. </script>
  38. </head>
  39. <body onload='onl()'>
  40. </body>
  41. </html>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.