Bar Graph Generator

S

Steve Darby

Hi all!

I wonder if anyone can help with a problem I am having with a sctipt I have
written. It uses the information stored in a cookie to generate a bar graph
of sales for a range of cooking pans. I have managed to read the cookie
information and draw the graph. The cookie is split and the values places
into two arrays. The cookie however, stores information on the preferences
for a text resizing facility in addition to the pan sales information. This
produces some unrequired information to be written to the graph. The
contents of the cookie is as follows:

sales=pan1=23,pan3=153,pan4=21,pan9=5; style=default

I only wish to use the information up to the semicolon, that is everything
other than style=default. How can I whilst splitting the cookie into the
two arrays, discard the unwanted information? Any help would be greatfully
received. Many thanks in advance. The script appears below:

<script language="javascript" type="text/javascript">

var array1 = new Array();
var array2 = new Array();
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.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);

document.write("<h2><u>"+array1[0]+"<\/u><\/h2><table>")
for (j=1; j<array1.length; j++) {
document.write("<tr><td><p><br><\/p><h3>"+array1[j]+"<\/h3><\/td><\/tr>")
document.write("<tr><td><img src='images/lilBlue.gif' height='20'
width='"+(array2[j-1]*3)

+"'>")
document.write("&nbsp;&nbsp;"+array2[j-1]+"<\/td><\/tr>")
}
document.write("<\/table>")

</script>
 
S

Steve Darby

Hi there,

Thanks for your reply. I managed to chieve the result I wanted by altering
the line:

var what = unescape(document.cookie);

to

var what = unescape(document.cookie.split("; "")[0]);

which splits the two cookie and selects only the first to be acted on by the
following code.

Many thanks again for your initial help. It is very much appreciated.

Regards,

Steve



McKirahan said:
Steve Darby said:
Hi all!

I wonder if anyone can help with a problem I am having with a sctipt I have
written. It uses the information stored in a cookie to generate a bar graph
of sales for a range of cooking pans. I have managed to read the cookie
information and draw the graph. The cookie is split and the values
places
into two arrays. The cookie however, stores information on the preferences
for a text resizing facility in addition to the pan sales information. This
produces some unrequired information to be written to the graph. The
contents of the cookie is as follows:

sales=pan1=23,pan3=153,pan4=21,pan9=5; style=default

I only wish to use the information up to the semicolon, that is
everything
other than style=default. How can I whilst splitting the cookie into the
two arrays, discard the unwanted information? Any help would be greatfully
received. Many thanks in advance. The script appears below:

<script language="javascript" type="text/javascript">

var array1 = new Array();
var array2 = new Array();
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.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);

document.write("<h2><u>"+array1[0]+"<\/u><\/h2><table>")
for (j=1; j<array1.length; j++) {
document.write("<tr><td><p><br><\/p><h3>"+array1[j]+"<\/h3><\/td><\/tr>")
document.write("<tr><td><img src='images/lilBlue.gif' height='20'
width='"+(array2[j-1]*3)

+"'>")
document.write("&nbsp;&nbsp;"+array2[j-1]+"<\/td><\/tr>")
}
document.write("<\/table>")

</script>


Change the assignment of "what" to include the last line below:

var what = unescape(document.cookie);
what = what.substr(what.indexOf("=")+1);
what = what.substr(0,what.indexOf(";"));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,078
Latest member
MakersCBDBlood

Latest Threads

Top