Create cookie

Hi,

I would like to create a cookie to store the values of stid, ctidand chid

how can I do this?
var fldMap={DispStateBox:'stid',GetCity:'ctid',GetChurch:'chid'};
function selectChurch(theSel){
  var theForm = theSel.form;
  for(var fldName in fldMap){
    window[fldMap[fldName]]=theForm[fldName].value;
  }

//here I would like to create a cookie to store the values 
of stid, ctidand chid
?

  self.location.href='home.cfm?stid='+stid+'&ctid='+ctid+'&chid='+chid;
}

Open in new window

lulu50Asked:
Who is Participating?
 
Lee SavidgeCommented:
Here is everything you need: http://www.w3schools.com/js/js_cookies.asp
0
 
lulu50Author Commented:

var fldMap={DispStateBox:'stid',GetCity:'ctid',GetChurch:'chid'};
function selectChurch(theSel){
  var theForm = theSel.form;
  var exdate=new Date();
  
  for(var fldName in fldMap){
    window[fldMap[fldName]]=theForm[fldName].value;
  }
  

exdate.setDate(exdate.getDate() + 30);
var stid=stid + ((30==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=stid + "=" + stid;

//how can I see the value of my cookie?
  
 // self.location.href='home.cfm?stid='+stid+'&ctid='+ctid+'&chid='+chid;
}

Open in new window

0
 
lulu50Author Commented:
//how can I see the value of my cookie?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Gurvinder Pal SinghCommented:
this link explains how to get and set the values of cookies
http://www.w3schools.com/js/js_cookies.asp
0
 
lulu50Author Commented:
gurvinder372:

I think i set it wrong.

I don't see it in my alert?

exdate.setDate(exdate.getDate() + 30);
var stid=stid + ((30==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=stid + "=" + stid;

var ctid=ctid + ((30==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=ctid + "=" + ctid;

var chid=chid + ((30==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=chid + "=" + chid;

alert(document.cookie);
0
 
Gurvinder Pal SinghCommented:
what do you see in the alert?
0
 
lulu50Author Commented:

gurvinder372:

I changed my code to this because I just want it to be simple

document.cookie=stid + "=" +escape(stid)+
((30==null) ? "" : ";expires="+exdate.toGMTString());

and did an alert

alert(document.cookie);

I see other cookies set but not stid
0
 
lulu50Author Commented:
I see it now!!

gurvinder372:
this link explains how to get and set the values of cookies
http://www.w3schools.com/js/js_cookies.asp

the same answer

lsavidge:
Here is everything you need: http://www.w3schools.com/js/js_cookies.asp
0
 
lulu50Author Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.