473,386 Members | 1,733 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,386 software developers and data experts.

convert string to object reference - avoiding eval

I was told on this site eval was bad but its the only way i can work out how to do it.. their example was
use var imdesc = document.myform[imagename1].value
not var imdesc = eval("document.myform." + imagename1 + ".value")
but i could not see how to change mine to emulate it...

I have a function displaytable() which i pass the id of a div into so:

displaytable(MyLayer1) - shows the first table hidden in the <div id=MyLayer1>
displaytable(MyLayer2) - shows the second table etc

So in my updatetemplate function I used eval to pass the string version of the object when the relevent menu item is selected:


Expand|Select|Wrap|Line Numbers
  1. function updatetemplate()
  2. {
  3.     var dropdown = document.form1.template;
  4.     var thenumber = dropdown.options[dropdown.selectedIndex].value;
  5.  
  6.     eval ( 'displaytable(MyLayer' + thenumber + ')' ) 
  7. }
  8.  

The function then passes the object and changes its display method
Expand|Select|Wrap|Line Numbers
  1. function displaytable(xxx)
  2. {
  3.     xxx.style.display = "block"
  4.  
  5.  
I'm not sure which bit to change.. I've tried lots of things and they all just make it fall over. The eval is the only way ive got it to work.

e.g. i tried this to no avail .. just get "expecting object" error:

Expand|Select|Wrap|Line Numbers
  1.     var convertit = document.['MyLayer'+thenumber]
  2.     displaytable( convertit ) ;
Jan 6 '06 #1
1 5718
acoder
16,027 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. var div = document.getElementById("MyLayer"+thenumber);
  2. displaytable(div);
should work fine.
Oct 1 '07 #2

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

Similar topics

16
by: flyaflya | last post by:
a = "(1,2,3)" I want convert a to tuple:(1,2,3),but tuple(a) return ('(', '1', ',', '2', ',', '3', ')') not (1,2,3)
5
by: JimMenees | last post by:
I know there's an easy answer to this which is escaping me: -------------------------------------------------------------------------- ----------------------- I have clickable thumb images which...
2
by: SimonZ | last post by:
Hi, can someone explain me, when to use: (DateTime)DataBinder.Eval(Container.DataItem, "dateField") OR Convert.ToDateTime(DataBinder.Eval(Container.DataItem, "dateField")) Sometimes...
4
by: MrDeej | last post by:
Anybody now if i can do this programtically? My challenge is that i have a maybe 10 distributions a week with updates and changes which i now have found the accde format to be of good use. I also...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.