473,657 Members | 3,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Splitting cookie

Can anyone help with this problem. I am attempting to dynamically draw a
graph using data from a cookie. I have written the script to actually draw
the graph, for which I hav created two arrays with the data I required
preset into them. What I wish to do is split the cookie in which the data
is stored and create two array from it.

The function used to create the cookie is as follows

:function SetCookie(name, value) {
document.cookie = name + "=" + escape(value);
}

which is called with the following script:

<body onload="SetCook ie('sales','pan 1=23,pan3=153,p an4=21,pan9=5') ">

I wish to create the following arrays by splitting the cookie:

array1=("sales" ,"pan1","pan3", "pan4","pan 9")
array2=(23,153, 21,5)

Can anyone help? Many thanks in advance.

Jul 23 '05 #1
11 1673
"Steve Darby" <ra************ ****@ntlworld.c om> wrote in message
news:cY******** ******@newsfe6-win.ntli.net...
Can anyone help with this problem. I am attempting to dynamically draw a
graph using data from a cookie. I have written the script to actually draw the graph, for which I hav created two arrays with the data I required
preset into them. What I wish to do is split the cookie in which the data
is stored and create two array from it.

The function used to create the cookie is as follows

:function SetCookie(name, value) {
document.cookie = name + "=" + escape(value);
}

which is called with the following script:

<body onload="SetCook ie('sales','pan 1=23,pan3=153,p an4=21,pan9=5') ">

I wish to create the following arrays by splitting the cookie:

array1=("sales" ,"pan1","pan3", "pan4","pan 9")
array2=(23,153, 21,5)

Can anyone help? Many thanks in advance.


What does your function "SetCookie( )" look like?
Jul 23 '05 #2
Like this:

function SetCookie(name, value) {
document.cookie = name + "=" + escape(value);
}

Jul 23 '05 #3
"Steve Darby" <ra************ ****@ntlworld.c om> wrote in message
news:In******** *******@newsfe6-win.ntli.net...
Like this:

function SetCookie(name, value) {
document.cookie = name + "=" + escape(value);
}


If you do:
alert(unescape( document.cookie ));

do you get this?
sales=pan1=23,p an3=153,pan4=21 ,pan9=5

Jul 23 '05 #4
"Steve Darby" <ra************ ****@ntlworld.c om> wrote in message
news:In******** *******@newsfe6-win.ntli.net...
Like this:

function SetCookie(name, value) {
document.cookie = name + "=" + escape(value);
}

Are you sure that you don't want:

array1=("pan1", "pan3","pan4"," pan9")
array2=(23,153, 21,5)

isntead of:

array1=("sales" ,"pan1","pan3", "pan4","pan 9")
array2=(23,153, 21,5)

thus array1[0] and array2[0] will correspond to "pan1" and "23".
Jul 23 '05 #5
I need 'sales' to be in array1 as well as the rest as it is used to form the
heading of the bar chart
Jul 23 '05 #6
"Steve Darby" <ra************ ****@ntlworld.c om> wrote in message
news:aH******** ******@newsfe6-win.ntli.net...
I need 'sales' to be in array1 as well as the rest as it is used to form the heading of the bar chart

Will this work for you?

<html>
<head>
<title>namevals .htm</title>
<script type="text/javascript">
var array1 = new Array();
var array2 = new Array();
function GetCookie() {
var what = unescape(docume nt.cookie);
array1[0] = what.substr(0,w hat.indexOf("=" ));
what = what.substr(wha t.indexOf("=")+ 1);
var pair = what.split(",") ;
var j = 1;
var k = 0;
for (var i=0; i<pair.length; i++) {
var item = pair[i].split("=");
array1[j++] = '"' + item[0] + '"';
array2[k++] = item[1];
}
// display contents of both arrays:
what = unescape(docume nt.cookie);
what += "\n\n array1 = " + array1.join("," );
what += "\n\n array2 = " + array2.join("," );
alert(what);
}
function SetCookie(name, value) {
document.cookie = name + "=" + escape(value);
}
</script>
</head>
<body onload="SetCook ie('sales','pan 1=23,pan3=153,p an4=21,pan9=5') ">
<a href="javascrip t:GetCookie()"> Get Cookie</a>
</body>
</html>
Jul 23 '05 #7
Will try it and let you know

"McKirahan" <Ne**@McKirahan .com> wrote in message
news:IL******** ************@co mcast.com...
"Steve Darby" <ra************ ****@ntlworld.c om> wrote in message
news:aH******** ******@newsfe6-win.ntli.net...
I need 'sales' to be in array1 as well as the rest as it is used to form

the
heading of the bar chart

Will this work for you?

<html>
<head>
<title>namevals .htm</title>
<script type="text/javascript">
var array1 = new Array();
var array2 = new Array();
function GetCookie() {
var what = unescape(docume nt.cookie);
array1[0] = what.substr(0,w hat.indexOf("=" ));
what = what.substr(wha t.indexOf("=")+ 1);
var pair = what.split(",") ;
var j = 1;
var k = 0;
for (var i=0; i<pair.length; i++) {
var item = pair[i].split("=");
array1[j++] = '"' + item[0] + '"';
array2[k++] = item[1];
}
// display contents of both arrays:
what = unescape(docume nt.cookie);
what += "\n\n array1 = " + array1.join("," );
what += "\n\n array2 = " + array2.join("," );
alert(what);
}
function SetCookie(name, value) {
document.cookie = name + "=" + escape(value);
}
</script>
</head>
<body onload="SetCook ie('sales','pan 1=23,pan3=153,p an4=21,pan9=5') ">
<a href="javascrip t:GetCookie()"> Get Cookie</a>
</body>
</html>

Jul 23 '05 #8
Have run the script and the alert returns the following:

array1=,"","pan 3","pan4","pan9 "
array2=,153,21, 5;style

And I should have mention that I am using script which allows me to change
text size on the page and saves the prefered values as a cookie, hence the
appearance of style in the second array. I am trying only to the
information listed for sales, if that makes sense
Jul 23 '05 #9
"Steve Darby" <ra************ ****@ntlworld.c om> wrote in message
news:iY******** *******@newsfe6-win.ntli.net...
Have run the script and the alert returns the following:

array1=,"","pan 3","pan4","pan9 "
array2=,153,21, 5;style

And I should have mention that I am using script which allows me to change
text size on the page and saves the prefered values as a cookie, hence the
appearance of style in the second array. I am trying only to the
information listed for sales, if that makes sense

Would you change
alert(what);
to
document.write( what);
and post the results here.
Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5284
by: Shannon Jacobs | last post by:
I'm doing some trivial surveys, and I want to know if the same user answers twice. Can't really know that, but at least I thought I could check for the same browser/computer combination by using a cookie. Here is the code I have now. In the header, I have the following: <SCRIPT language="JavaScript"> var cookieStatus; if (document.cookie.length > 0) { cookieStatus = 'Cookie exists with value ' + document.cookie; } else {
12
17972
by: chrism | last post by:
Hello, I have a pop-up window that I would like to appear in front of the browser home page when a user opens IE. Problem is, I'd like it to never appear again if the user navigates back to the home page during their time using the browser. However, if the user closes the browser, then reopens, the pop-up should appear again. (you may have guessed that this will be used for public access pc's.) I want to try as best I can to catch...
5
3310
by: brettr | last post by:
When I reference document.cookie, there is a long string of key=value; pairs listed. I may have 100 hundred cookies on my hard drive. However, most only have one key=value pair. Does the document.cookie variable combine all cookie key=value pairs? All of the examples I've seen discuss referencing a specific cookie. I don't see how this is done. Cookies are usually named by the domain. If I want to reference a specific cookie, do I...
4
3806
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"> if(document.cookie.indexOf("beenHere1=true")!=-1) else
9
4486
by: Marco Krechting | last post by:
Hi All, I have a page with a list of hyperlinks. I want to save information in a cookie about the fact that I entered an hyperlink or not. When I click one of the hyperlinks I want this stored in a cookie and a small bullit shown in front of the hyperlink, so when I reload the page I can immediately see which hyperlinks I already visited that day.
3
11110
by: Wysiwyg | last post by:
After a server created cookie is processed on the client I want it removed, cleared, or expired in the javascript block but have been unable to do this. If I set a cookie value in the server code behind and don't use a domain then I can not change or remove that cookie's value on the client. If I subsequently create the cookie again in the codebehind then I actually end up with TWO cookies with the same name in the response. The cookie...
1
6696
by: CR1 | last post by:
I found a great cookie script below, but don't know how to make it also pass the values sent to the cookie, to a querystring as well for tracking purposes. Can anyone help? If there was a way to simply pass the values in a cookie to the querystring that would be even easier, but from what I've been able to tell, cookie values can't be passed to a querystring. I'm sure the answer will help alot of others who are using this script, and would...
6
2695
by: kelvlam | last post by:
Hello all, I'm still a bit new with JavaScript, and I hope the guru here can shed some light for me. It's regarding handling cookie and the case-sensitive nature of JavaScript itself. My problem is how do I handle the "path" parameter in cookie. First, the sequence start at http://www.testServer1.com/TestApp/page1.htm, and a cookie is set at
2
3264
by: shadow_ | last post by:
Hi i m new at C and trying to write a parser and a string class. Basicly program will read data from file and splits it into lines then lines to words. i used strtok function for splitting data to lines it worked quite well but srttok isnot working for multiple blank or commas. Can strtok do this kind of splitting if it cant what should i use . Unal
0
8302
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8820
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8499
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8601
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7314
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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 we have to send another system
2
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.