javascript Global eval( )
| eval( ) | NN 2 IE 3 ECMA 1 |
eval("string") | |
|
Returns an object reference of the object described as a string in the parameter of the function. For example, if a form has a sequence of text fields named entry1, entry2, entry3, and so on, you can still use a for loop to cycle through all items by name if you let the eval( ) function convert the string representation of the names to object references: for (var i = 1; i<=5; i++) {
oneField = eval("document.forms[0].entry" + i);
oneValue = oneField.value;
...
}
|
|
Be aware, however, that the eval( ) method is perhaps the most inefficient and performance-draining method of the entire JavaScript language. There are many other, far more efficient, ways to reference a document tree object when you have only the string ID or name, such as the document.getElementById( ) and, for older browsers, named indexes of the document.forms, document.images, and document.formRef.elements arrays. |
|
| Parameters | |
|
|
| Returned Value | |
Object reference. |
|
