Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 03-04-2007, 07:22 AM   #1
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
Old 03-04-2007, 07:26 AM   #2
Angelo22
Writer
 
Angelo22's Avatar
 
Industry Role:
Join Date: Feb 2007
Posts: 3,123
looks like it just places the second number after the first one without adding it...

good luck finding a solution
__________________
MAKE MORE MONEY FROM YOUR WEB TRAFFIC - 15% BONUS

And contact me if you need high quality translating and writing work done - angelo22 (AT) gmail (DOT) com
Angelo22 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-04-2007, 11:29 AM   #3
Quickdraw
Confirmed User
 
Join Date: Mar 2004
Location: → → →
Posts: 1,717
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
Quickdraw is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.