eval function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • amohajer@hotmail.com

    eval function

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

  • Dag Sunde

    #2
    Re: eval function

    <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]

    RTFM...



    :)

    --
    Dag.


    Comment

    • Michael Winter

      #3
      Re: eval function

      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]

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

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

      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.

      Comment

      • Daniel M. Hendricks

        #4
        Re: eval function

        <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:

        <button onclick="select All('myDropDown ')" />Highlight Dropdown
        #1</button>


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

        Daniel M. Hendricks


        Comment

        • Jim Ley

          #5
          Re: eval function

          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...

          Jim.

          Comment

          • Dr John Stockton

            #6
            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.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]

            But also newsgroup FAQ sec 4.40.

            --
            © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
            <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
            <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
            <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

            Comment

            • Douglas Crockford

              #7
              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.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

              Working...