Возникли проблемы с созданием корзины покупок?
Здравствуйте, я хочу сделать корзину покупок, создав две разные веб-страницы под названием товар и корзина. Когда вы нажмете кнопку Добавить в корзину на странице товаров, она не появится на странице корзины, так что вы можете мне помочь здесь?? ЗАРАНЕЕ БЛАГОДАРЮ ВАС!!
Что я уже пробовал:
Здесь cart.html
<table width="100%" border="0"> <tr> <td valign="top" width="50%"> <table cellpadding="4" cellspacing="4" border="1"> <tr> <td valign="top"> <table cellpadding="4" cellspacing="4" border="1" id="orderedProductsTbl"> <thead> <tr> <td> Name </td> <td> Description </td> <td> Price </td> </tr> </thead><pre>
Деталь : 0 Итого: 0 6% налога: 0 сумма: 0
Здесь mechandise.html
<table width="100%" border="0"> <tr> <td valign="top" width="50%"> <table cellpadding="4" cellspacing="4" border="1"> <tr> <td valign="top"> <table cellpadding="4" cellspacing="4" border="0"> <thead> <tr> <td colspan="2"> Products for sale </td> </tr> </thead> <tbody> <tr> <td> Table </td> <td> <form action="cart.html" method="post"> <p><input type="submit" value="Add to cart" onclick="AddtoCart('Table','Big red table',50)"/></p> </form> </td> </tr> <tr> <td> Door </td> <td> <input type="submit" value="Add to cart" onclick="AddtoCart('Door','Yellow Door',150)" action="cart.html" method="post" /> </td> </tr> <tr> <td> Car </td> <td> <input type="submit" value="Add to cart" onclick="AddtoCart('Ferrari','Ferrari S234',150000)" action="cart.html" method="post" /> </td> </tr> </tbody> </table> </td> </tr> </table> </td> </tr> </table>
вот это JavaScript
var shoppingCart = []; //this function manipulates DOM and displays content of our shopping cart function displayShoppingCart(){ var orderedProductsTblBody=document.getElementById("orderedProductsTblBody"); //ensure we delete all previously added rows from ordered products table while(orderedProductsTblBody.rows.length>0) { orderedProductsTblBody.deleteRow(0); } //variable to hold total price of shopping cart var cart_total_price=0; //iterate over array of objects var cart_item = 0; var tax = 0.00; var total = 0; for(var product in shoppingCart){ //add new row var row=orderedProductsTblBody.insertRow(); //create three cells for product properties var cellName = row.insertCell(0); var cellDescription = row.insertCell(1); var cellPrice = row.insertCell(2); cellPrice.align="right"; //fill cells with values from current product object of our array cellName.innerHTML = shoppingCart[product].Name; cellDescription.innerHTML = shoppingCart[product].Description; cellPrice.innerHTML = shoppingCart[product].Price; cart_total_price+=shoppingCart[product].Price; tax= (.06) * (cart_total_price); total = (tax) + (cart_total_price); cart_item++; } document.getElementById("cart_total_item").innerHTML=cart_item; document.getElementById("tax_total").innerHTML = tax; //fill total cost of our shopping cart document.getElementById("cart_total").innerHTML=cart_total_price; document.getElementById("final_total").innerHTML=total; } function AddtoCart(name,description,price){ //Below we create JavaScript Object that will hold three properties you have mentioned: Name,Description and Price var singleProduct = {}; //Fill the product object with data singleProduct.Name=name; singleProduct.Description=description; singleProduct.Price=price; //Add newly created product to our shopping cart shoppingCart.push(singleProduct); //call display function to show on screen displayShoppingCart(); }