SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Add onclick dynamically

    I have a group of radio buttons like so:

    HTML Code:
    <input TYPE=radio NAME=Array Value=8> Blue<br>
    <input TYPE=radio NAME=Array Value=9> Orange<br>
    <input TYPE=radio NAME=Array Value=10> Yellow<br> 
    <input TYPE=radio NAME=Array Value=11> Ruby
    I want to add an onclick event dynamically, I tried with this approach:

    Code JavaScript:
    var radios = document.getElementsByName("Array");
    for(var i=0; i<radios.length; i++) {
    	radios[i].onclick = finish();
    }

    Instead of adding the onclick event, it just fires the function four times when the page loads. Also tried radios[i].onclick = "finish();"; but to no avail. Any ideas on the matter or reasons what I'm doing wrong?

  2. #2
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    336
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Remove the parenthesis from finish();

  3. #3
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, I'm still learning and completely forgot about needing to address the function that way!


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
  •