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

eval() question

I've got the following complete web page...

<html><head>
<script>
var allElements={};
function addElements() {
for( var idx=0; idx < addElements.arguments.length; idx++ ) {
allElements[addElements.arguments[idx]]=0;
}
}
function initializeElements() {
for( elem in allElements ) {
eval( elem+"=document.getElementById( '"+elem+"' );" );
}
}
addElements( 'foo' );
function ready() {
initializeElements();
}
</script></head>
<body onload="ready()">
<input type="text" id="foo" size="1">
</body></html>

I'm basically trying to make declaring variables to store document
nodes easier. This all works, except that for some reason the eval()
says "Object doesn't support this property or method". The eval() is
supposed to introduce a variable at global scope named elem - what is
the problem?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 23 '05 #1
2 997
Christopher Benson-Manica wrote:
I'm basically trying to make declaring variables to store document
nodes easier. This all works, except that for some reason the eval()
says "Object doesn't support this property or method". The eval() is
supposed to introduce a variable at global scope named elem - what is
the problem?


Forget about using eval(), you can do without:

function initializeElements() {
for (elem in allElements) {
window['elem'] = document.getElementById(elem);
}
}
JW

Jul 23 '05 #2
Janwillem Borleffs <jw@jwscripts.com> wrote:
Forget about using eval(), you can do without: window['elem'] = document.getElementById(elem);


Thank you!

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Mike | last post by:
After reading much on the evils of eval, I have a question using my own personal use of the function... We have a reports system that will generate reports based on a number of parameters...
11
by: sneill | last post by:
I have read a number of posts on the use of eval() in Javascript, and I agree that its use is questionable. But it does beg the following question: "How arbitrary does a string need to be before...
18
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
3
by: Mark Jones | last post by:
I am quite new to ASP and .Net development and I am building a web-based multiple choice exam application. The web page displays the questions using a Repeater control and the answers are nested...
4
by: CharlesA | last post by:
a general question... I'm a bit mystified by Databinder.eval(object, Colname, ) if controls can be bound to their individual data sources within the load event of the page... why would we ever...
13
by: Stephen Kay | last post by:
Is there a way to redirect every single page on an existing web site through a php function? In other words, say I have a whole functional HTML web site, never written to use any php. Now I...
5
by: iulian.ilea | last post by:
Hi, I have to eval a string stored in a variable, but it's not working. code: ___ function ee($s) { return $s; }
8
by: sonet | last post by:
Many Language have eval function.The C have eval function? How to execute c code in c ? Can i execute c code from a variable(like perl's code ref)? Or i must do this job by using yacc & lex ? All...
6
by: vasudevram | last post by:
Hi group, Question: Do eval() and exec not accept a function definition? (like 'def foo: pass) ? I wrote a function to generate other functions using something like eval("def foo: ....") but...
10
by: Gordon | last post by:
I have a script that creates new objects based on the value of a form field. Basically, the code looks like this. eval ('new ' + objType.value + '(val1, val2, val3'); objType is a select with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.