<amohajer@hotma il.com> wrote in message
news:1102918795 .967434.167160@ z14g2000cwz.goo glegroups.com.. .[color=blue]
> what does eval function do in javascript language and what are its
> usages?[/color]
On Mon, 13 Dec 2004 07:30:56 GMT, Dag Sunde <me@dagsunde.co m> wrote:
[color=blue]
> <amohajer@hotma il.com> wrote in message
> news:1102918795 .967434.167160@ z14g2000cwz.goo glegroups.com.. .
>[color=green]
>> what does eval function do in javascript language and what are its
>> usages?[/color]
>
> RTFM...
>
> http://developer.netscape.com/librar...avascript.html[/color]
Basically, it allows you to construct and run statements at run-time.
However, there are *very* few instances where you actually need to use
eval; there are usually much better ways of accomplishing the same thing.
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
<amoha...@hotma il.com> wrote:
[color=blue]
> what does eval function do in javascript language and what are its
> usages?[/color]
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.fo rm.'+dd);
for (var i=0;i<box.optio ns.length;i++) { box.options[i].selected=true;
}
}
In this example, "eval('var box=document.fo rm.'+dd);" would evaluate to
"var box=document.fo rm.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:
On 13 Dec 2004 07:11:06 -0800, "Daniel M. Hendricks"
<dmhendricks@de spammed.com> wrote:
[color=blue]
><amoha...@hotm ail.com> wrote:
>[color=green]
>> what does eval function do in javascript language and what are its
>> usages?[/color]
>
>Here is an example usage.
>
>This is especially useful for dynamically created controls that may
>have dynamic names.[/color]
Maybe you should read the FAQ, before giving any more answers, just in
case the correct answer is there...
JRS: In article <Qybvd.6978$HA5 .807198@juliett .dax.net>, dated Mon, 13
Dec 2004 07:30:56, seen in news:comp.lang. javascript, Dag Sunde
<me@dagsunde.co m> posted :[color=blue]
><amohajer@hotm ail.com> wrote in message
>news:110291879 5.967434.167160 @z14g2000cwz.go oglegroups.com. ..[color=green]
>> what does eval function do in javascript language and what are its
>> usages?[/color][/color]
[color=blue]
>http://developer.netscape.com/librar...avascript.html[/color]
>>what does eval function do in javascript language and what are its[color=blue][color=green]
>>usages?[/color][/color]
[color=blue]
> 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.fo rm.'+dd);
> for (var i=0;i<box.optio ns.length;i++) { box.options[i].selected=true;
> }
> }
>
> In this example, "eval('var box=document.fo rm.'+dd);" would evaluate to
> "var box=document.fo rm.myDropDown".[/color]
The only advantage to using eval in this way is that it might allow a
very slow-witted scripter to avoid learning about the subscript notation.
function selectAll(dd) {
var box = document.form[dd];
It is almost always wrong to use the eval function.
Comment