473,508 Members | 2,477 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="SetCookie('sales','pan1=23,pan3=153,pan4=2 1,pan9=5')">

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

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

Can anyone help? Many thanks in advance.

Jul 23 '05 #1
11 1657
"Steve Darby" <ra****************@ntlworld.com> 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="SetCookie('sales','pan1=23,pan3=153,pan4=2 1,pan9=5')">

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

array1=("sales","pan1","pan3","pan4","pan9")
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.com> 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,pan3=153,pan4=21,pan9=5

Jul 23 '05 #4
"Steve Darby" <ra****************@ntlworld.com> 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","pan9")
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.com> 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(document.cookie);
array1[0] = what.substr(0,what.indexOf("="));
what = what.substr(what.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(document.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="SetCookie('sales','pan1=23,pan3=153,pan4=2 1,pan9=5')">
<a href="javascript: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********************@comcast.com...
"Steve Darby" <ra****************@ntlworld.com> 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(document.cookie);
array1[0] = what.substr(0,what.indexOf("="));
what = what.substr(what.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(document.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="SetCookie('sales','pan1=23,pan3=153,pan4=2 1,pan9=5')">
<a href="javascript:GetCookie()">Get Cookie</a>
</body>
</html>

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

array1=,"","pan3","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.com> wrote in message
news:iY***************@newsfe6-win.ntli.net...
Have run the script and the alert returns the following:

array1=,"","pan3","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
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:JZ********************@comcast.com...
"Steve Darby" <ra****************@ntlworld.com> wrote in message
news:iY***************@newsfe6-win.ntli.net...
Have run the script and the alert returns the following:

array1=,"","pan3","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.

Rather just add the following after the alert():

what = unescape(document.cookie);
what += "<br><br> array1 = " + array1.join(",");
what += "<br><br> array2 = " + array2.join(",");
document.write(what);
Here's what I get:

sales=pan1=23,pan3=153,pan4=21,pan9=5

array1 = sales,"pan1","pan3","pan4","pan9"

array2 = 23,153,21,5
Jul 23 '05 #11
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:JZ********************@comcast.com...
"Steve Darby" <ra****************@ntlworld.com> wrote in message
news:iY***************@newsfe6-win.ntli.net...
Have run the script and the alert returns the following:

array1=,"","pan3","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


I forgot the first element was supposed to quoted; try this:

<html>
<head>
<title>namevals.htm</title>
<script type="text/javascript">
var array1 = new Array();
var array2 = new Array();
function GetCookie() {
var what = unescape(document.cookie);
array1[0] = '"' + what.substr(0,what.indexOf("=")) + '"';
what = what.substr(what.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];
}
what = unescape(document.cookie);
what += "<br><br> array1 = " + array1.join(",");
what += "<br><br> array2 = " + array2.join(",");
document.write(what);
}
function SetCookie(name,value) {
document.cookie = name + "=" + escape(value);
}
</script>
</head>
<body onload="SetCookie('sales','pan1=23,pan3=153,pan4=2 1,pan9=5')">
<a href="javascript:GetCookie()">Get Cookie</a>
</body>
</html>
You should get this:

sales=pan1=23,pan3=153,pan4=21,pan9=5

array1 = "sales","pan1","pan3","pan4","pan9"

array2 = 23,153,21,5
Jul 23 '05 #12

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

Similar topics

4
5273
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...
12
17944
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...
5
3302
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...
4
3791
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">...
9
4465
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...
3
11097
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...
1
6684
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...
6
2686
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...
2
3251
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...
0
7133
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...
0
7336
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,...
0
7405
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
7066
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
7504
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...
1
5059
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
3198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
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 ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.