473,467 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Setting cookies in JavaScript?

36 New Member
Hi Guys

I think I have a really easy one for you.

I am currently using the following script to store information in cookies:

-------------SCRIPT--------------
<%
response.cookies("prefs")("make")="Aston Martin"
response.cookies("prefs")("model")="Vanquish"
response.cookies("prefs")("price")="£40000"
For Each cookie in Response.Cookies
Response.Cookies(cookie).Expires = now()+365
Next
%>
-------------END-------------

This works just fine in my ASP pages but now I need to incorporate the same method into some xml pages and therefore believe I need to use Javascript. I have spent hours reading numerous (how to set cookies in Javascript) articles and have not found a simple example that matches what I want to achieve above.

Can anyone please put me out of my misery and provide me with a simple piece of code that I can use in my xml page to achieve the above?

If so, then that would be great.

I look forward to hearing from you

Rod from the UK
Sep 27 '07 #1
2 1393
dmjpro
2,476 Top Contributor
Hi Guys

I think I have a really easy one for you.

I am currently using the following script to store information in cookies:

-------------SCRIPT--------------
<%
response.cookies("prefs")("make")="Aston Martin"
response.cookies("prefs")("model")="Vanquish"
response.cookies("prefs")("price")="£40000"
For Each cookie in Response.Cookies
Response.Cookies(cookie).Expires = now()+365
Next
%>
-------------END-------------

This works just fine in my ASP pages but now I need to incorporate the same method into some xml pages and therefore believe I need to use Javascript. I have spent hours reading numerous (how to set cookies in Javascript) articles and have not found a simple example that matches what I want to achieve above.

Can anyone please put me out of my misery and provide me with a simple piece of code that I can use in my xml page to achieve the above?

If so, then that would be great.

I look forward to hearing from you

Rod from the UK

Look this is a Java Forum.
Java!=JavaScript :-)
So post the code in JavaScript forum.
And have a look at this code ......
Expand|Select|Wrap|Line Numbers
  1. function createCookie(name,value,days) {
  2.     if (days) {
  3.         var date = new Date();
  4.         date.setTime(date.getTime()+(days*24*60*60*1000));
  5.         var expires = "; expires="+date.toGMTString();
  6.     }
  7.     else var expires = "";
  8.     document.cookie = name+"="+value+expires+"; path=/";
  9. }
  10.  
  11. function readCookie(name) {
  12.     var nameEQ = name + "=";
  13.     var ca = document.cookie.split(';');
  14.     for(var i=0;i < ca.length;i++) {
  15.         var c = ca[i];
  16.         while (c.charAt(0)==' ') c = c.substring(1,c.length);
  17.         if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  18.     }
  19.     return null;
  20. }
  21.  
  22. function eraseCookie(name) {
  23.     createCookie(name,"",-1);
  24. }
  25.  
Good Luck with your try :-)

Kind regards,
Dmjpro.
Sep 27 '07 #2
rjoseph
36 New Member
Sorry

I posted my problem the wrong forum.

Best regards

Rod from the UK
Sep 27 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: John Taylor-Johnston | last post by:
I'm a University academic looking for a proper definition of JavaScript Cookies. http://www.CollegeSherbrooke.qc.ca/languesmodernes/604-HAE_Grammar_Practice/ I'm trying to decipher what...
1
by: Timur Tabi | last post by:
I have an embedded system with a web interface. One of the web pages has a small JavaScript program that, when run on IE6, always displays the message that cookies need to be enabled: if...
1
by: Mike | last post by:
I got the code below from an earlier post but I can't get it to work (I get an error on the "for (i=0; i<a.length; i++)" line) Anyone have code that works for cookies with keys? > Anyone...
4
by: socialism001 | last post by:
I'm trying to store a value in a cookie but its not working. Can anyone see what I might be doing wrong. Thanks, Chris ~~~~~~~~~~~~~~~~~~ <script language="javascript">...
1
by: Jose Olivas | last post by:
I am setting a cookie on a subdomain: http://store1.mydomain.com Then the store takes me to a shopping cart that is at: http://shopping.mydomain.com Somewhere the following code (taken and...
9
by: SHarris | last post by:
Hello, In our new intranet ASP.NET project, two requirements are that the browser accept cookies AND JavaScript. We are requiring the use of Internet Explorer 6+. 1. Using C# in an ASP.NET...
2
by: junlia | last post by:
Hi All, I am working on a project that acts as a bridge. It does some checking with post xml data, and then redirects the request to an appropriate page. However, we find that depends on the...
0
by: rjoseph | last post by:
Hi Guys I think I have a really easy one for you. I am currently using the following script to store information in cookies: -------------SCRIPT-------------- <%...
3
by: obarash | last post by:
I need to set a ParentCookie wich will include sub childern Example (in ASP): response.cookies("testCookie")("test1") = "186" response.cookies("testCookie")("test2") = "140" in this way i can...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.