The eval() function is a global function. This means it does not need dot notation to be used. You just type in eval(), not document.eval().

It takes a string and executes that string as if it were a javascript statement. Therefore you can use variables and portions of statements, combine them to get an executable statement.

This allows the developer to use less code, more functions to accomplish the same tasks.

This example only works with NS4. (because that's what I wrote it for)

Hide lyr1

lyr1

make sure you properly nest your quotes

 

Also, because early browsers have the most problems with the DOM (document object model), this will allow you to work with (and include) every browser into your scripting.

 

The eval statement works with every version of browser. It allows you to evolve a script on the fly. Just remember to nest your quotes --

i.e.: double quotes, then outside of that, single quotes, outside of that, double quotes.

You also need to escape some ascii characters. -

 

eval( 'document.' + layerName + '.visibility = "hide"' )

These can get more complicated when you work with strings, keeping track of how the browser will interpret the html escapes you choose.