?
Solved

Create cookie

Posted on 2011-10-18
9
Medium Priority
?
342 Views
Last Modified: 2012-06-27
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

0
Comment
Question by:lulu50
  • 6
  • 2
9 Comments
 
LVL 25

Accepted Solution

by:
Lee Savidge earned 1000 total points
ID: 36984880
Here is everything you need: http://www.w3schools.com/js/js_cookies.asp
0
 

Author Comment

by:lulu50
ID: 36984926

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
 

Author Comment

by:lulu50
ID: 36984928
//how can I see the value of my cookie?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Assisted Solution

by:Gurvinder Pal Singh
Gurvinder Pal Singh earned 1000 total points
ID: 36984954
this link explains how to get and set the values of cookies
http://www.w3schools.com/js/js_cookies.asp
0
 

Author Comment

by:lulu50
ID: 36984969
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
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 36984974
what do you see in the alert?
0
 

Author Comment

by:lulu50
ID: 36984986

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
 

Author Comment

by:lulu50
ID: 36985013
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
 

Author Closing Comment

by:lulu50
ID: 36985015
Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question