SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Jul 2004
    Location
    Salem, OR
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question assigned attribute through DOM, onclick. Does not inclick in IE 6.x

    Hi

    I have an issue. In a nutshell I am making and inserting into a the DOM of a page a button:

    Code:
    _button = document.createElement("input");
    _button.setAttribute("type","button");
    _button.setAttribute("id","button");
    _button.setAttribute("value","Remove");
    _button.setAttribute("onClick","alert('');");
    It gets assigned to its parent:

    Code:
    _parent.appendChild(_button);
    And all is well in FF 1.5 or 2.0. But in IE 6.x the button appears in the DOM, but the JavaScript 'onclick' is never invoked. Help!

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    IE doesn't support attaching event handlers with setAttribute(). I rarely use setAttribute(). Also, event names should be all lowercase.

    Code:
    _button.onclick = function(){ alert(''); }
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    SitePoint Addict
    Join Date
    Jul 2004
    Location
    Salem, OR
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Yep, that was it and thanks for the info on keeping in lowercase (is that part of a specification or something).

    I have another for you that has been puzzling me. I have a multidimensional array inside a for loop

    Code:
    for(var i = 0; i < availableArray.length; i++){
       ...
    }
    I've noticed that if I try to pass something like:

    Code:
       availableArray[i][0]
    As a parameter, even to alert like:

    Code:
       alert(availableArray[i][0]);
    I get an error, but if I do

    Code:
       alert(availableArray[0][0]);
    It works. Again this just happens in IE not FF.

  4. #4
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    JavaScript is case sensitive.

    As for the multidimensional array, I suspect the problem lies elsewhere. We might be able to help you with that if you could show us more of your code.

    This works, right?
    Code:
    var myAr = [
      ['zoo','bar'],
      ['zoo','bar'],
      ['bar','foo']
    ];
    
    for(var i = 0; i < myAr.length; i++){
      alert(myAr[i][0]);
    }
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  5. #5
    SitePoint Addict
    Join Date
    Jul 2004
    Location
    Salem, OR
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Kravitz

    First off, (and I wanted to send this message even before your most recent reply) thanks so much for your help.

    Secondly, yes your example works. I did however solve the problem through a different route, but to help. The array I was attempting to access was a argument to a function. It seemed that within the function to which it was passed you could access the dynamic array i.e.,

    Code:
    function somefunction(paramarray){
       somevalue = paramarray[0][0];
       ...somecode..
    }
    var thisarray = new Array();
    thisarray[0][0] = somevalue;
    somefunction(thisarray);
    Would work, but if you tried:

    Code:
    function somefunction(paramarray){
       anotherfunction(paramarray[0][0]);
    }
    
    function anotherfunction(paramarrayvalue){
       ...some code...
    }
    It would throw an error.

    Like I said I took a different approach in the end, and haven't had the time to tinker more on this theme to figure out what went wrong.

    Don't feel the need to spend any real time on the issue though, it was just an odd stumbling block.


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
  •