Connecting Tech Pros Worldwide Forums | Help | Site Map

eval function

amohajer@hotmail.com
Guest
 
Posts: n/a
#1: Jul 23 '05
what does eval function do in javascript language and what are its
usages?


Dag Sunde
Guest
 
Posts: n/a
#2: Jul 23 '05

re: eval function


<amohajer@hotmail.com> wrote in message
news:1102918795.967434.167160@z14g2000cwz.googlegr oups.com...[color=blue]
> what does eval function do in javascript language and what are its
> usages?[/color]

RTFM...

http://developer.netscape.com/librar...avascript.html

:)

--
Dag.


Michael Winter
Guest
 
Posts: n/a
#3: Jul 23 '05

re: eval function


On Mon, 13 Dec 2004 07:30:56 GMT, Dag Sunde <me@dagsunde.com> wrote:
[color=blue]
> <amohajer@hotmail.com> wrote in message
> news:1102918795.967434.167160@z14g2000cwz.googlegr oups.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]

However, that manual doesn't exist any more. :P

<URL:http://docs.sun.com/source/816-6408-10/toplev.htm#1063795>

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.
Daniel M. Hendricks
Guest
 
Posts: n/a
#4: Jul 23 '05

re: eval function


<amoha...@hotmail.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.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

Jim Ley
Guest
 
Posts: n/a
#5: Jul 23 '05

re: eval function


On 13 Dec 2004 07:11:06 -0800, "Daniel M. Hendricks"
<dmhendricks@despammed.com> wrote:
[color=blue]
><amoha...@hotmail.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...

Jim.
Dr John Stockton
Guest
 
Posts: n/a
#6: Jul 23 '05

re: eval function


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.com> posted :[color=blue]
><amohajer@hotmail.com> wrote in message
>news:1102918795.967434.167160@z14g2000cwz.googleg roups.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]

But also newsgroup FAQ sec 4.40.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Douglas Crockford
Guest
 
Posts: n/a
#7: Jul 23 '05

re: eval function


>>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.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".[/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.

http://www.crockford.com/javascript/survey.html
Closed Thread