Click to See Complete Forum and Search --> : using associative Arrays to process cookies


Alan
02-14-2003, 02:27 PM
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

Alan
02-14-2003, 04:05 PM
Hi Dave

That was an excellent response time. Wow!
(I posted on a Compuserve forum over 4 days
ago and still haven't had a response - obviously
the experts are lurking here :-)

Thanks to your help I've not got it to work:-

for (var loop in the_info)
{
var the_property = loop;
var the_value = the_info[loop];
}

Clean and simple.

Now, any ideas how, having set the fields on a form:

visioLoadWait = ""+ the_info["visioLoadWait"];
pageLoadWait = ""+ the_info ["pageLoadWait"];
pageZoomWait = ""+ the_info ["pageZoomWait"];

I get the form display to be refreshed?
(if I reload the form then I would revert to the fixed values defined in the form)

Alan

Alan
02-14-2003, 05:35 PM
Dave

Spot on! I had forgotten the .value

All now working. You're a great help.

I can see some bells and whistels
but must leave it alone<g>.

I wouldn't have half these problems if I didn't need to have these waits while the page loads
and refeshes but I see lots of code doing timer
waits. It all seem haphazard, especially if some
users are using the app over a fast LAN, others
over a slow dial-up and many in-between. JS
seems lacking in this respect (i.e. events to
say when a page is rendered) - or have I missed something?

Alan
P.S. Now just the IE6 online problem to solve (see other thread) and it's finished.