I am having trouble printing my cookie array onto a reveiw cart page. Here is th
ID: 3551394 • Letter: I
Question
I am having trouble printing my cookie array onto a reveiw cart page. Here is the code I have.
var cookie_val = new Array();
function setCookies(key,book,price)
{//all forms must have all info to set to a var. then the var set to the cookie.
var amount = document.exercise_form.item.value;
var r=confirm("Add " + book + " to cart?");
if (r==true)
{
//Set the cookie
document.cookie = key + "=" + book + "=" + price + "=" + amount;
}
}
function processCookies()
{var my_cookie = unescape(document.cookie);
var cookie_array= my_cookie;
var length=cookie_array.length;
var i =0;
for(i=0; i < length; i++){
cookie_val=cookie_array[i].split("=");
}
window.open("store_index.htm");
}
function print()
{
var length=cookie_val.lenght;
var i =0;
for(i=0; i < length; i++){
document.write(myArray[i]);
}
}
Here some error i have
Explanation / Answer
Answer:
I think the first error is beacuse of "document.exercise_form.item.value".
and rest of the errors have been removed.
print() funtion was changed to print2().
var cookie_val = new Array();
function setCookies(key,book,price)
{//all forms must have all info to set to a var. then the var set to the cookie.
var amount = document.exercise_form.item.value;
var r=confirm("Add " + book + " to cart?");
if (r==true)
{
//Set the cookie
document.cookie = key + "=" + book + "=" + price + "=" + amount;
}
}
function processCookies()
{var my_cookie = unescape(document.cookie);
var cookie_array= my_cookie;
var length=cookie_array.length;
var i =0;
for(i=0; i < length; i++)
{
cookie_val[i]=cookie_array[i].split("=");
}
window.open("store_index.htm");
}
function print2()
{
var length=cookie_val.length;
var i =0;
for(i=0; i < length; i++){
document.write(cookie_val[i]);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.