Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: How do you attach an event listener to radio button using javascript

  1. #11
    Join Date
    Jul 2008
    Posts
    128
    Thanks
    0
    Thanked 17 Times in 16 Posts

    Default

    Quote Originally Posted by jscheuer1 View Post

    I kind of cringe a little though when I see a for loop where a while loop would work,
    They compile identically and the for loop could be said to make its operation clearer.

    also when I see i++ when ++i would work.
    When used as a for loop action I see no difference between them.

    Limiting the loop by the existence of the element will fail in some older Mozilla script engines.
    Which don't exist due to the browser being self-updating.

  2. #12
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Time trials prove that while and pre incrementing/decrementing are more efficient than for and post incrementing/decrementing. And that iterating from the last to the first is also more efficient than from first to last. Incidentally, in some cases it actually makes more logical sense to iterate backwards, like if you're removing items from an array or nodeList while iterating over it - if you go forwards, the iteration process loses track of the count.

    However, both things I said - that it's a fine point and that with a small number of items to iterate over it makes little or no difference, apply here.

    It's a good practice to get into though because you have no way to know for sure when the code you write will get applied in a situation where the number of items is great enough to warrant iterating over them in the most efficient manner possible.

    About looping on existence - Those older Moz browsers are out there though, they were made before the self updating craze began. Self updating can easily be opted out of as well, and might need to be in certain environments.

    However, I would agree that we are talking about a limited number of browsers, probably mostly on older computers - mostly owned by people/schools/other organizations with either limited financial means and/or limited knowledge of I.T. But I still like the idea of supporting folks like that, especially those of limited financial means, more so than the others, but them too.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #13
    Join Date
    Jul 2013
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    thank you so much for your help on this matter. It worked.

    warm regards

    Andreea

Similar Threads

  1. How to select a radio button using javascript?
    By rishirich4y in forum JavaScript
    Replies: 14
    Last Post: 11-09-2011, 01:04 AM
  2. Replies: 1
    Last Post: 06-11-2010, 08:38 AM
  3. event listener not working
    By farridav in forum JavaScript
    Replies: 1
    Last Post: 03-23-2010, 09:16 AM
  4. Replies: 4
    Last Post: 05-05-2007, 09:22 PM
  5. file attach to flash button
    By xeno in forum Other
    Replies: 2
    Last Post: 04-07-2006, 05:32 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •