C
Christopher Benson-Manica
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?
<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?