[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Set a cookie in JavaScript ...

Posted on 2000-01-27
4
Medium Priority
?
208 Views
Last Modified: 2013-12-25
how do i set a cookie with javascript that has more than one value I know how to set them in VBScript ie:

(set a cookie called C_Name that will store first & last name and age)...

Response.Cookies("C_Name")("FName")= "xxx"
Response.Cookies("C_Name")("LName")= "xxx"
Response.Cookies("C_Name")("Age")= "xxx"


Then to retrieve the info stored in the cookie:

first = Request.Cookies("C_Name")("FName")
last = Request.Cookies("C_Name")("LName")
u_age = Request.Cookies("C_Name")("Age")


Thanks
0
Comment
Question by:r_fritz
  • 3
4 Comments
 

Author Comment

by:r_fritz
ID: 2394033
need a quick response. will up the points to 150 if i get a answer by 5:00 p.m. today (1/27/00)
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 2396766
===========================================
<SCRIPT LANGUAGE="JavaScript">
<!--
//Standard function, from InternetWorld
function GetCookie (name) {  
  var arg = name + "=";  
  var alen = arg.length;  
  var clen = document.cookie.length;  
  var i = 0;  

  while (i < clen) {    
    var j = i + alen;    
    if (document.cookie.substring(i, j) == arg)      
      return getCookieVal (j);    

    i = document.cookie.indexOf(" ", i) + 1;    
    if (i == 0) break;    
  }  
  return null;
}

//Standard function, from InternetWorld
function getCookieVal(offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

//Standard function, from InternetWorld
function SetCookie (name, value) {  
  var argv = SetCookie.arguments;  
  var argc = SetCookie.arguments.length;  
  var expires = (argc > 2) ? argv[2] : null;  
  var path = (argc > 3) ? argv[3] : null;  
  var domain = (argc > 4) ? argv[4] : null;  
  var secure = (argc > 5) ? argv[5] : false;  
  document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +  
    ((domain == null) ? "" : ("; domain=" + domain)) +    
    ((secure == true) ? "; secure" : "");
}

//Standard function, from InternetWorld
function DeleteCookie (name) {  
  var exp = new Date();  
  exp.setTime (exp.getTime() - 1);  
  // This cookie is history  
  var cval = GetCookie (name);  
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
==================================

These are your standard JS cookie functions.

CJ
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 2501295
Did this help r_fritz?

CJ
0
 
LVL 19

Accepted Solution

by:
cheekycj earned 200 total points
ID: 2524021
I am posting as an answer because I believe I did answer the Q.

CJ
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

By following these Magento e-commerce development tips, you can increase your website's conversion and profitability. Read this post for more details.
Magento is the best technology for eCommerce start-ups as it offers the technical expertise and visual appeal to create a store that pulls sales and earns high ROI (Return on investment).
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month11 days, 2 hours left to enroll

612 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