using associative Arrays to process cookies

admin

Administrator
Staff member
Hi
I would appreciate some help having spent some hours with no progress. I've copied and adapted a *generalised* javascript for managing cookies.
(maybe I should of hard coded it <g>)

Reading - this works OK:
for (var loop = 0; loop < separated_values.length; loop++) {
property_value = separated_values[loop];
var broken_info = property_value.split(":");
var the_property = broken_info[0];
var the_value = broken_info[1];
the_info[the_property] = the_value;
}

Setting - this works OK, although it is app specific code (it would be nice to have it generalised):
the_info ["visioLoadWait"] = visioLoadWait;
the_info ["pageLoadWait"] = pageLoadWait;
the_info ["pageZoomWait"] = pageZoomWait;

Saving - doesn't work:
for (var loop = 0; loop < the_info.length; loop++) {
var the_property = the_info[loop];
var the_value = the_info[the_info[the_info[loop]]];
the_cookie = the_cookie + escape(the_property+ ":" + the_value + "/");
}

The cookie string comes out as: ....=undefined:undefined/:undefined/:undefined/;.....

The original downloaded code was:
for (var loop = 0; loop < the_info.length; loop++) {
property_value = the_info[loop];
var broken_info = property_value.split(":");
var the_property = broken_info[0];
var the_value = broken_info[1];
the_cookie = the_cookie + escape(the_property+ ":" + the_value + "/");
}
which is strange as the the_info stored items are surely not of the form "name:value"
and anyway the property_value = the_info[loop]; gives an error:
"property_value is null or is not an object"

I have read on the web that one can't mix the forms the_info ["name"] and the_info [n]
but also read that the two forms are equally valid. However, without the the_info [n]
form then it seems to me generalised code is not possible.

One other problem, when reading the cookie and assigning the values to form
fields how to I get the screen to show the new read values - it continues to show the
values in the original page.

I thought this would be simple but as you see
I'm in a muddle. Any help much appreciated.

Alan
UK
 
Back
Top