<amoha...@hotmail.com> wrote:
what does eval function do in javascript language and what are its
usages?
Here is an example usage. Let's say I have several drop-down menu and
certain buttons/events that require all items in the dropdown be
highlighted. Here is a thrown-together example of a highlight
function:
function selectAll(dd) {
eval('var box=document.form.'+dd);
for (var i=0;i<box.options.length;i++) { box.options[i].selected=true;
}
}
In this example, "eval('var box=document.form.'+dd);" would evaluate to
"var box=document.form.myDropDown". Now, if a user clicked a button
and I wanted it to highlight all the fields in the dropdown named
'myDropDown', you could use something like this:
<button onclick="selectAll('myDropDown')" />Highlight Dropdown
#1</button>
This is especially useful for dynamically created controls that may
have dynamic names.
Daniel M. Hendricks
http://www.danhendricks.com