473,322 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

eval function

what does eval function do in javascript language and what are its
usages?

Jul 23 '05 #1
6 2487
<am******@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
what does eval function do in javascript language and what are its
usages?


RTFM...

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

:)

--
Dag.
Jul 23 '05 #2
On Mon, 13 Dec 2004 07:30:56 GMT, Dag Sunde <me@dagsunde.com> wrote:
<am******@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
what does eval function do in javascript language and what are its
usages?


RTFM...

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


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.
Jul 23 '05 #3
<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

Jul 23 '05 #4
On 13 Dec 2004 07:11:06 -0800, "Daniel M. Hendricks"
<dm*********@despammed.com> wrote:
<amoha...@hotmail.com> wrote:
what does eval function do in javascript language and what are its
usages?


Here is an example usage.

This is especially useful for dynamically created controls that may
have dynamic names.


Maybe you should read the FAQ, before giving any more answers, just in
case the correct answer is there...

Jim.
Jul 23 '05 #5
JRS: In article <Qy*******************@juliett.dax.net>, dated Mon, 13
Dec 2004 07:30:56, seen in news:comp.lang.javascript, Dag Sunde
<me@dagsunde.com> posted :
<am******@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googleg roups.com...
what does eval function do in javascript language and what are its
usages?
http://developer.netscape.com/librar...avascript.html


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.
Jul 23 '05 #6
>>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".


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
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jean-Sébastien Bolduc | last post by:
Hello, I would like to associate a local namespace with a lambda function. To be more specific, here is exactly what I would want: def foo(): a = 1 f = lambda x : a*x return f
9
by: HikksNotAtHome | last post by:
This is a very simplified example of an Intranet application. But, is there an easier (or more efficient) way of getting the decimal equivalent of a fraction? The actual function gets the select...
12
by: knocte | last post by:
Hello. I have always thought that the eval() function was very flexible and useful. If I use it, I can define functions at runtime!! However, I have found a case where eval() does not work...
18
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
3
by: Pauljh | last post by:
Hi All, I'm running some javascript over a server side generated web page and have multiple generated empty select statements, that I want to populate when the page is loaded. As HTML doesn't do...
7
by: Darko | last post by:
Hello, I have this particular problem with eval() when using Microsoft Internet Explorer, when trying to define an event handler. This is the code: function BigObject() { this.items = new...
6
by: vasudevram | last post by:
Hi group, Question: Do eval() and exec not accept a function definition? (like 'def foo: pass) ? I wrote a function to generate other functions using something like eval("def foo: ....") but...
2
by: Florian Loitsch | last post by:
hi, What should be the output of the following code-snippet? === var x = "global"; function f() { var x = 0; eval("function x() { return false; }"); delete x; alert(x); }
6
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with...
10
by: Gordon | last post by:
I have a script that creates new objects based on the value of a form field. Basically, the code looks like this. eval ('new ' + objType.value + '(val1, val2, val3'); objType is a select with...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.