473,327 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

javascript eval() IE

107 100+
Hey,

Im at my wits end!

Im trying to get IE to store a string that defines a multi-demensional array as an actual array.

Heres what the array definition would look like:
Expand|Select|Wrap|Line Numbers
  1. foo = Array(    {'key' : 'value', 'key2' : 'value2'},{'key' : 'value', 'key2' : 'value2'},    {'key' : 'value', 'key2' : 'value2'},    {'key' : 'value', 'key2' : 'value2'});
  2. alert(foo[1]["key"]);
  3.  
No problem!

but i have this stored as a string (without the foo = part). So im using eval() to evaluate the code. It's worked in most combinations i've tried in firefox no problems but none in IE. Heres some of what ive tried:

Expand|Select|Wrap|Line Numbers
  1. foo = "Array(    {'key' : 'value', 'key2' : 'value2'},{'key' : 'value', 'key2' : 'value2'},    {'key' : 'value', 'key2' : 'value2'},    {'key' : 'value', 'key2' : 'value2'});";
  2.  
  3. foo = "\"Array(    {\"key\" : \"value\", \"key2\" : \"value2\"},{\"key\" : \"value\", \"key2\" : \"value2\"},    {\"key\" : \"value\", \"key2\" : \"value2\"},    {\"key\" : \"value\", \"key2\" : \"value2\"});\";";
  4.  
  5. foo = "\"Array(    {'key' : 'value', 'key2' : 'value2'},{'key' : 'value', 'key2' : 'value2'},    {'key' : 'value', 'key2' : 'value2'},    {'key' : 'value', 'key2' : 'value2'});\"";
  6.  
  7.  
  8. myarray = eval(foo);
  9. alert(myarray[1]["key"]);
  10.  

To further complicate things, some of the values in the array sometimes have ' characters in, however i just want to get it working without first then i can probably just add slashes to solve that problem.

Any Help is much apprieciated!

Andy
Mar 12 '08 #1
3 4825
gits
5,390 Expert Mod 4TB
hi ...

i just tested it in IE6 addressbar:

Expand|Select|Wrap|Line Numbers
  1. javascript:var a = eval("Array(   {'key' : 'value', 'key2' : 'value2'},{'key' : 'value', 'key2' : 'value2'}, {'key' : 'value', 'key2' : 'value2'},    {'key' : 'value', 'key2' : 'value2'});"); alert(a[0].key);
that was your first showed option and it alerted 'value' as it would be expected? ... what IE version do you use? is any error shown?

kind regards
Mar 12 '08 #2
theS70RM
107 100+
oh yea, should have thought about testing it like that,

turns out it was a problem with my variable name and another class that i wrote conflicting.

Thanks for your help!
Mar 12 '08 #3
gits
5,390 Expert Mod 4TB
no problem ;) ... post back to the forum anytime you have more questions ...

kind regards
Mar 12 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: JesusFreak | last post by:
From: us_traveller@yahoo.com (JesusFreak) Newsgroups: microsoft.public.scripting.jscript Subject: toolbar script problem NNTP-Posting-Host: 192.92.126.136 Recently, I downloaded the following...
7
by: Marci | last post by:
I found this script for cascading menus, however, I cannot reach the author to solve the bug I am having when I add a second menu to it. My problem is this: If I click on the first link, the...
4
by: binnyva | last post by:
Hello Everybody, I am writing an interactive tutorial for JavaScript. I created a text box into which the users can input javascript commands. On pressing a button, these commands will be...
3
by: jimmygoogle | last post by:
I posted earlier with a scope problem. I think I resolved it in IE but in Firefox it still exists. Anyone have any ideas/experience with this? I attached my code sorry it is so long. You can...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.