View Single Post
Old 03-04-2007, 07:22 AM  
SkeetSkeet
Confirmed User
 
SkeetSkeet's Avatar
 
Join Date: Oct 2005
Location: StarlightBucks !
Posts: 5,404
Help With Cookies

Asking help for a friend :


I've been having problems setting up a simple javasript. I've just been trying to get a better understanding of cookies...
overall problem: I need to add a new value to a cookie.

The script below has an if statement that will either add to the cookie or start a new cookie.

Example:
if (document.cookie){
CODE IF COOKIE EXISTS
}else{
CODE IF COOKIE DOES NOT EXIST}

My problem is this:
I want to add "old_cookie" + "new_value"... however,
It only adds to the cookie.
example:
old_cookie = 1;
new_value = 2;
new_cookie = 1 + 2;
// I want it to return 3, however it returns 12...

Also, if I add another value
example:
old_cookie now equals = 12;
new_value = 1;
new_cookie = 12 + 1;
//it will return 121;

Furthermore, if I replace '+' with any other symbol (ie: *, /, -, etc.) it will work just fine...
example:
old_cookie = 2;
new_value = 3;
new_cookie = 2 * 3;
//it returns 6;

---------------------------------------
<script language="JavaScript">
<!-- This will add item to cart

function process(){
if(document.cookie && document.cookie != ""){
var old_cookie = document.cookie;
var new_value = document.form.quantity.value;
var new_cookie = old_cookie + new_cookie;

document.cookie = escape(new_cookie);
}
else{

var new_data = document.form.quantity.value;
document.cookie = escape(new_data);
}

alert(unescape(document.cookie ));
}

function kill_cookie(){
document.cookie = "";
}

-->
</script>
__________________

ICQ 283633188
SkeetSkeet is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote