www.webdeveloper.com
Results 1 to 6 of 6

Thread: setAttribute and onClick

  1. #1
    Join Date
    May 2007
    Posts
    10

    setAttribute and onClick

    With googling I have found that IE does not support setAttribute and onClick, so I tried the alternative recommended below using lowercase onclick = a function, but nothing is being inserted into my radio button, just the name and type=radio. Anyone know how I might remedy this? Thanks so much.

    Code:
          var SizeRadio1 = document.createElement("input");
          SizeRadio1.setAttribute("type","radio");
          SizeRadio1.setAttribute("name","breedFinderChoice");
    
          SizeRadio1.onclick = function () {changeDropDown(i,'size_id')};                    
    
          var rec1 = document.createElement("div");
          rec1.style.cssText = "color:#336;margin 4px 0px 2px 0px;";    
          rec1.appendChild(SizeRadio1); 
         .... rest of code to append some text to rec1
    Last edited by cactusPhone; 07-24-2007 at 11:53 AM.

  2. #2
    Join Date
    Apr 2007
    Posts
    71
    You are missing
    Code:
    document.body.appendChild(rec1);
    rec1.appendChild(SizeRadio1);
    If it's still don't work then your function changeDropDown(i,'size_id') is not good.
    Try to debug with
    Code:
    SizeRadio1.onclick = function () {alert('something')};

  3. #3
    Join Date
    Jun 2007
    Posts
    347
    Yes.

    SizeRadio1.onclick = function () {changeDropDown(i,'size_id')};

    If this is being done inside a loop in a function, you will end up with a closure. i will always be the value of i after loop exit.

  4. #4
    Join Date
    May 2007
    Posts
    10
    Quote Originally Posted by Banana Ananda
    Yes.

    SizeRadio1.onclick = function () {changeDropDown(i,'size_id')};

    If this is being done inside a loop in a function, you will end up with a closure. i will always be the value of i after loop exit.
    Thanks so much! That was it. I see my error now with the timing of the function call.

  5. #5
    Join Date
    May 2007
    Posts
    10
    The radio button in IE does fire the event, but does not show as being selected when clicked. Do I need to write into the function an event to make the radio button selected?
    Last edited by cactusPhone; 07-24-2007 at 01:54 PM.

  6. #6
    Join Date
    Jun 2007
    Posts
    347
    but does not show as being selected when clicked.
    I can't see why. Do you have some example code to play with ?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles