GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Help With Cookies (https://gfy.com/showthread.php?t=711517)

SkeetSkeet 03-04-2007 07:22 AM

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>

Angelo22 03-04-2007 07:26 AM

looks like it just places the second number after the first one without adding it...

good luck finding a solution

Quickdraw 03-04-2007 11:29 AM

Quote:

if(document.cookie && document.cookie != ""){
var old_cookie = document.cookie;
var new_value = document.form.quantity.value;
var new_cookie = old_cookie + new_cookie;
A note on the above-- it appears to have new_value as what is in the form, but when adding the old_cookie to new_cookie, in "var new_cookie", it isn't used.

Anyway, as far as adding those digits, you can either multiply each by one, or use the Number function.
var new_cookie = old_cookie * 1 + new_value * 1;
or
var new_cookie = Number(old_cookie) + Number(new_value);

Good luck


All times are GMT -7. The time now is 09:06 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123