/    Sign up×
Community /Pin to ProfileBookmark

removing items from multiple cookies?

Hi, I have multiple cookies with names “Part Id” “Quantity” and “Price”. I have successfully passed the inputted data to a cookie and display it on another page. Quantity is a field the user enters a quantity into, Part ID and Price are hidden fields that have a specific Part ID and Price. I want, on the second page (shoppingCart) to be able to remove items from the order and then refresh the page with the items gone.

The remove function sees which boxes are still checked and puts them into the cookies, leaving out the nonchecked items and effectively deleting them. This is how I name the checkboxes:

document.write (“<input type=”checkbox” name=”parts” checked “);
document.write(“value=”” + order_array[i] + “”>”);

On the first page, I create the cookies by taking the values from the hidden and the nonhidden (quantity) fields like so:
<script language=”javascript”>
function parts(new_item){

order_string = order_string + “xxx” + new_item ;
document.cookie =”Part ID=” + escape(order_string);

//end if

}//ends function

var quantity_string = “”;
function quantity(new_item){

quantity_string = quantity_string + “xxx” + new_item;
document.cookie = “Quantity=” + escape(quantity_string);

}//ends function

var price_string = “”;
function price(new_item){

price_string = price_string + “xxx” + new_item;
document.cookie = “Price=” + escape(price_string);

}//ends function
</script>

Assuming that that code is right, here is how I have my remove function currently, the problem being that the function seems to be skipping directly to the KillCookies() function, so nothing is being inserted into clean_cookie_function I think. Maybe it’s the way I have my checkboxes named or something, I can’t figure it out:

function remove()
{

var new_cookie_stuff = “drop this”;
var quantity_stuff= “drop it”;
var price_stuff = “drop them”;

if(document.orderform.parts)
{

for(i=0; i<document.orderform.parts.length; i++)
{
if(document.orderform.parts[i].checked == “true”)
{

new_cookie_stuff= new_cookie_stuff + document.orderform.parts[i].value+”xxx”;
quantity_stuff = quantity_stuff + quantity_array[i] + “xxx”;
price_stuff = price_stuff + price_array[i] + “xxx”;
}//end of if
}//end of for
}//end of if
var clean_cookie_string_1 = new_cookie_stuff.split(“drop this”);
var clean_cookie_string = clean_cookie_string_1[1];
var clean_quantity_string_1 = quantity_stuff.split(“drop it”);
var clean_quantity_string = clean_quantity_string_1[1];
var clean_price_string_1 = price_stuff.split(“drop them”);
var clean_price_string = clean_price_string_1[1];

if(clean_cookie_string != “”)
{
document.cookie = “Part Id=” + escape(clean_cookie_string);
alert(document.cookie);
document.cookie = “Quantity=” + escape(clean_cookie_string);
document.cookie = “Price=” + escape(clean_cookie_string);
alert(document.cookie);
window.location(“shoppingCart.html”);

}//ends if

if(clean_cookie_string == “”) {kill_cookies()}

}//end of remove function

Any help would be very appreciated!

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @haunsolo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...