Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

[JS]Call an array from another function

Status
Not open for further replies.

WouterP

Programmer
Aug 24, 2003
3
NL
Hello,

I made a page that creates a cookie with multiple properties/ values. when I recall the cookie I split them up and put them into an assiociative array.
but when I try to recall them IE gives &quot;error: stored_info is not defined&quot;. I have placed &quot;<<<<<<<<&quot; where the error occurs.

code to create cookie
Code:
//create cookie
var cookie_inhoud = &quot;test1:1~test1:2&quot;
document.cookie = &quot;test_cookie=&quot; + escape(cookie_inhoud);

code to get the cookie information
Code:
//get cookie
function getCookie() {
var original_cookie = document.cookie;
var decoded_cookie = unescape(original_cookie);
//remove cookie title
var cookie_splitted = decoded_cookie.split(&quot;=&quot;);
var cookie_contains = cookie_splitted[1];
//put the rest into an array
var cookie_contains_splitted = cookie_contains.split(&quot;~&quot;);
//split the rest with a loop
for (var loop = 0; loop < cookie_contains_splitted.length; loop++) {
var cookie_loop1 = cookie_contains_splitted[loop];
var cookie_loop2 = cookie_loop1.split(&quot;:&quot;);
var property = cookie_loop2[0];
var value = cookie_loop2[1];
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<error below
stored_info[property] = value;
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<error above
}
}

here I want to get information from stored_info, but then the error is given.
Code:
function test() {
stored_info = new Array();
getCookie(stored_info);
alert(stored_info[&quot;test1&quot;]);
}

I tried several other options and variables, but nothing seems to work.
I hope someone can help me out of this.

Wouter
 
I'm afraid I've never manipulated cookies from javascript, but these two faqs might help you:
faq216-1956
and
faq216-2297

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top