inefficient to check value of a checkbox?

Discussion in 'Javascript' started by Kourosh, May 26, 2006.

  1. Kourosh

    Kourosh Guest

    I have a big loop that checks the value of a checkbox several times
    (1000+ times)
    I'm just wondering, would it be any more efficient to save the value of
    the checkbox outside the loop and the read that variable inside the
    loop instead?

    ie, I have this
    for (var i=0;...)
    doStuff (form1.checkbox1.checked);


    versus
    var chk = form1.checkbox1.checked;
    for (var i=0;...)
    doStuff (chk);
     
    Kourosh, May 26, 2006
    #1
    1. Advertisements

  2. Kourosh

    Randy Webb Guest

    Kourosh said the following on 5/26/2006 2:54 PM:
    > I have a big loop that checks the value of a checkbox several times
    > (1000+ times)
    > I'm just wondering, would it be any more efficient to save the value of
    > the checkbox outside the loop and the read that variable inside the
    > loop instead?
    >
    > ie, I have this
    > for (var i=0;...)
    > doStuff (form1.checkbox1.checked);
    >
    >
    > versus
    > var chk = form1.checkbox1.checked;
    > for (var i=0;...)
    > doStuff (chk);
    >


    Do the second. It keeps from having to look up that property 1000 or so
    times and as such will *always* be faster.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, May 26, 2006
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. News
    Replies:
    17
    Views:
    571
    Larry Bates
    Apr 14, 2006
  2. Replies:
    10
    Views:
    1,087
    Mark Rae
    Dec 5, 2006
  3. Lone Wolf
    Replies:
    5
    Views:
    898
    Dennis Lee Bieber
    Dec 4, 2006
  4. Joshua J. Kugler

    Is shelve/dbm supposed to be this inefficient?

    Joshua J. Kugler, Aug 2, 2007, in forum: Python
    Replies:
    1
    Views:
    473
    Marc 'BlackJack' Rintsch
    Aug 2, 2007
  5. JB
    Replies:
    1
    Views:
    697
  6. Imran Aziz

    checkbox value attribute in checkbox control ?

    Imran Aziz, Aug 6, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    356
    Imran Aziz
    Aug 8, 2005
  7. Terje
    Replies:
    5
    Views:
    582
    Evertjan.
    Nov 18, 2004
  8. randy
    Replies:
    13
    Views:
    780
    Tad McClellan
    Nov 1, 2003
Loading...