/    Sign up×
Community /Pin to ProfileBookmark

Can’t create cookies

What I’m trying to do is save 9 values from drop down boxes on my page into 9 cookies. These are the scripts I’m trying to use. SaveDefault gets the intital values and loops through the box elements. MyCookie() saves the values and SetCookie in theory should create the cookies.

The string is getting to this.cook at the bottom, but document.cookies does not seem to be saving it to the cookies folder on my computer. I don’t know if it’s a problem with the format of the cookie or a simple syntax problem.

As a side note, I have got the request and response.cookie objects to work in asp, but would rather do this client side.

function SaveDefault(){
var objForm = document.forms[0];
for (var i=0; i<9; i++){
MyCookie(‘set’,objForm.elements[i].id,objForm.elements[i].value,’30’,”/”,””,””);
}
}

function MyCookie(action,name,value,expires,path,domain,secure){

var action = action;
this.name = name;
if(action == ‘set’){
this.value = value;
this.expires = (expires)?expires:’-1′;
this.path = path || ‘/’;
this.domain = domain || document.domain;
this.secure = secure || ”;
this.today = new Date();
this.expr = new Date(this.today.getTime() + (this.expires * 86400000));

}
if(action == ‘set’){ this.set_cookie = SetCookie(this); }
else if(action == ‘get’){ this.cookie_value = GetCookieValue(this); }
else if(action == ‘all’){ this.dump = GetAllCookies(); }
}

function SetCookie(objCookie){
this.cook = objCookie.name + “=” + escape(objCookie.value);
this.cook += “?expires=” + objCookie.expr.toGMTString();
this.cook += “?path=” + objCookie.path;
this.cook += “?domain=” + Cookie.domain;
this.cook += “?” + objCookie.secure;
document.cookie = this.cook;
}

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @eyeballl 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.28,
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,
)...