views:

43

answers:

2

I am implementing a shopping cart site. When the user add the item, it will automatically add to cart with the product name and the price as a div. the code is below

<div class="food_menu_add"><a href="#" id="ad"><img src="images/add.gif" onclick="addcart('Sliced Orange')" /></a></div>
<table id="placehold">
</table>

function addcart(name)
{
  var ni = document.getElementById('placehold');
  var newdiv = document.createElement('tr');
  var divIdName = 'myDiv';
  newdiv.setAttribute('id',divIdName);
  newdiv.innerHTML = name;
  ni.appendChild(newdiv);
}

When the image is clicked the <tr> is generating. i want to post the <tr> generated to the next page. How can i get that?. Plz help. Any help will be appreciated

+2  A: 

Put the contents into a hidden field in your form with javascript at the same time as you generate it so that it is posted along with your form. I assume there is submit button somewhere on the page in a form.

Treffynnon
Thanks! Great idea, Im gonna implement
Rajasekar
+1  A: 

How about this:

In order for the to be generated on the next page you would need to SAVE every time the user add an item.

You could use cookies, simply add the following line to your "addcart' function:

document.cookie =
  'item1=Sliced Orange; expires=Fri, 3 Aug 2011 20:47:11 UTC; path=/'

(Change the date, the name and the value :) So every time an user call addCart() it will save the item in a cookie.

Then add a new function to be executed on every page you would like. This one will load all the items from the cookies and generate the . You can call it in the html body tag:

<body onload="LoadCookies()">

And your LoadCookies() function would load each item and call the addCart() function.

Lobsterm