needhelp101
03-16-2012, 04:20 AM
I am creating a shopping cart application that stores and retrieves cookies. I have two pages created. the first page has a table containing two rows, in which the user checks that item, and enters in the quantity. after the user selects one or both items and enters in the quantity, they click the button Add to cart, which stores this as a cookie. when the user clicks the view cart link, it brings them to view what they ordered in a table. my problem is, when the user clicks on the view cart link, how do i get the table to be displayed as the item name in the first column, the quantity in the second column, price in the third column, and the total for that item in the last column? here is the code for both my pages
<html>
<head>
<title> Store </title>
<h1> My store </h1>
<script type="text/javascript">
function setCookie()
{
var exdate = new Date();
exdate.setDate(exdate.getDate() +10);
document.cookie = "price="+ document.getElementsByName("Price")[0].value + ";expires="+exdate.toGMTString();
}
function retrieve()
{
document.getElementsByName("fullName")[0].value = document.cookie;
}
function Calc()
{
if (document.getElementById("calcu")){
var pri = document.getElementById("price").value;
var qty = document.getElementById("quantity").value
Total(pri,qty)
}
}
function Total(pri, qty)
{
var pri = document.getElementById("price").value
var qty = document.getElementById("quantity").value
if (document.getElementById("circle").checked) {
document.getElementById("total").value = pri * qty
}
}
functino load()
{
document.getElementById("circle")
}
</script>
</head>
<body>
<table border = "1">
<td> <input type="checkbox" id = "circle"> Circle </td>
<td> <img src="circle.jpg"> </td>
<td> Price: <input type = "text" size = "4" name = "price" />$ </td>
<td> Quantity: <input type = "text" size = "4" id = "quantity"/> </td>
<tr> </tr>
<td> <input type = "checkbox"> Stickman </td>
<td> <img src = "stickman.gif"> </td>
<td> Price: <input type = "text" size = "4" value = "$" id = "price" /> </td>
<td> Quantity: <input type = "text" size = "4" id = "quantity" /> </td>
</table>
<br />
<input type = "button" value = "Add to cart">
<br />
<br />
<a href ="cart.html" onclick = "retrieve()"> View Cart </a>
<br />
<input type = "text" size = "8" id = "total"readonly = "readonly" /> Total
<br />
<input type = "button" id = "calcu" value = "calc" onclick = "Calc()" />
</body>
</html>
<html>
<head>
<title> Cart </title>
<h1> My cart </h1>
<script type = "text/javascript">
function retrieve()
{
document.getElementsByName("price")[0].value =
document.cookie;
}
</script>
</head>
<body>
<table border = "1">
<td> Stickman </td>
<td> <script type = "text/javascript">document.getElementById
("price") </script> </td>
<td> price per </td>
<td> total </td>
<tr> </tr>
<td> Circle </td>
<td> quantity order </td>
<td> price per </td>
<td> total </td>
<tr> </tr>
<td colspan = "3"> TOTAL: </td>
<td> total price </td>
</table>
<br /> <br />
<script type="text/javascript">document.write(retrieve("price"));
</script>
<br / > <br />
<input type = "button" value = "Checkout">
<br /> <br />
<a href = "store.html"> Continue Shopping
</body>
</html>
for this code, where it says quantity ordered, its supposed to display the quantity the user entered. price per is displaying the price, and where it says total, the total of that item.
<html>
<head>
<title> Store </title>
<h1> My store </h1>
<script type="text/javascript">
function setCookie()
{
var exdate = new Date();
exdate.setDate(exdate.getDate() +10);
document.cookie = "price="+ document.getElementsByName("Price")[0].value + ";expires="+exdate.toGMTString();
}
function retrieve()
{
document.getElementsByName("fullName")[0].value = document.cookie;
}
function Calc()
{
if (document.getElementById("calcu")){
var pri = document.getElementById("price").value;
var qty = document.getElementById("quantity").value
Total(pri,qty)
}
}
function Total(pri, qty)
{
var pri = document.getElementById("price").value
var qty = document.getElementById("quantity").value
if (document.getElementById("circle").checked) {
document.getElementById("total").value = pri * qty
}
}
functino load()
{
document.getElementById("circle")
}
</script>
</head>
<body>
<table border = "1">
<td> <input type="checkbox" id = "circle"> Circle </td>
<td> <img src="circle.jpg"> </td>
<td> Price: <input type = "text" size = "4" name = "price" />$ </td>
<td> Quantity: <input type = "text" size = "4" id = "quantity"/> </td>
<tr> </tr>
<td> <input type = "checkbox"> Stickman </td>
<td> <img src = "stickman.gif"> </td>
<td> Price: <input type = "text" size = "4" value = "$" id = "price" /> </td>
<td> Quantity: <input type = "text" size = "4" id = "quantity" /> </td>
</table>
<br />
<input type = "button" value = "Add to cart">
<br />
<br />
<a href ="cart.html" onclick = "retrieve()"> View Cart </a>
<br />
<input type = "text" size = "8" id = "total"readonly = "readonly" /> Total
<br />
<input type = "button" id = "calcu" value = "calc" onclick = "Calc()" />
</body>
</html>
<html>
<head>
<title> Cart </title>
<h1> My cart </h1>
<script type = "text/javascript">
function retrieve()
{
document.getElementsByName("price")[0].value =
document.cookie;
}
</script>
</head>
<body>
<table border = "1">
<td> Stickman </td>
<td> <script type = "text/javascript">document.getElementById
("price") </script> </td>
<td> price per </td>
<td> total </td>
<tr> </tr>
<td> Circle </td>
<td> quantity order </td>
<td> price per </td>
<td> total </td>
<tr> </tr>
<td colspan = "3"> TOTAL: </td>
<td> total price </td>
</table>
<br /> <br />
<script type="text/javascript">document.write(retrieve("price"));
</script>
<br / > <br />
<input type = "button" value = "Checkout">
<br /> <br />
<a href = "store.html"> Continue Shopping
</body>
</html>
for this code, where it says quantity ordered, its supposed to display the quantity the user entered. price per is displaying the price, and where it says total, the total of that item.