PDA

View Full Version : javascript array problems



scottybowl
05-25-2006, 09:20 AM
i have the array


SPECIAL_DAYS = {

};


i want to put the value of "results" into SPECIAL_DAYS, results contains the following (results is a variable from the result of an AJAX call):



"2006-5" : [ 5 ],
"2006-6" : [ 3 ],
"2006-7" : [ 7 ],
"2006-8" : [ 4 ],
"2006-9" : [ 2 ],
"2006-10" : [ 6 ],
"2006-11" : [ 4 ],
"2007-0" : [ 1 ],
"2007-1" : [ 5 ],
"2007-2" : [ 5 ],
"2007-3" : [ 2 ],
"2007-4" : [ 7 ],
"2007-5" : [ 4 ],
"2007-6" : [ 2 ],
"2007-7" : [ 6 ],
"2007-8" : [ 3 ],
"2007-9" : [ 1 ],
"2007-10" : [ 5 ]


i'm stumped, any suggestions?

Twey
05-25-2006, 09:24 AM
One of the rare instances where the eval() call is appropriate, methinks.

scottybowl
05-25-2006, 09:29 AM
i'm relatively new to javascript so no doubt people across the world will slap their foreheads when they see what i tried!



SPECIAL_DAYS = {
eval(results);
};


This (probably not surprisingly) didnt work...

Twey
05-25-2006, 09:40 AM
I think:
eval("SPECIAL_DAYS = { " + results + " };");would work better. :)

scottybowl
05-25-2006, 10:05 AM
thanks, that worked :)

scottybowl
05-30-2006, 08:51 AM
oops, that works in FireFox but not in Internet Explorer, it causes an "Undefined Error" :(

scottybowl
05-30-2006, 09:21 AM
ah, i think ive pinpointed the problem..

I'm using an http.open request to send all the fields in a form to a PHP file, it works perfectly in Firefox, but in IE it gives an error - is there a maximum string length that can be used in an http.open call?

Twey
05-30-2006, 11:27 AM
Not insofar as I know.