Results 1 to 7 of 7

Thread: [RESOLVED] DOM differences between IE and everything else

  1. #1

    Thread Starter
    Hyperactive Member BillGeek's Avatar
    Join Date
    Jun 2006
    Location
    Canada
    Posts
    440

    Resolved [RESOLVED] DOM differences between IE and everything else

    I was experimenting with AJAX a bit yesterday and actually got it working in FireFox. When I wanted to see whether it still works in IE, I was not surprised when it didn't.

    There seems to be a major difference in DOM Scripting between IE and the other browsers. For example, see the following code:
    Code:
    var cTotalReturn = xmlHttp.responseText;
    var cPostId = cTotalReturn.substring(0, cTotalReturn.indexOf("|"));
    var cPostText = cTotalReturn.substring(cTotalReturn.indexOf("|") + 1);
    
    // Get all elements by specific names
    var myQuickPosts = document.getElementsByName("ajaxQuickPost");
    var myEditButtons = document.getElementsByName("ajaxEditButton");
    var myQuoteButtons = document.getElementsByName("ajaxQuoteButton");
    var myPostIds = document.getElementsByName("ajaxShowPostId");
    var myPostTexts = document.getElementsByName("ajaxPostText");
    var myPostTitles = document.getElementsByName("ajaxPostTitle");
    
    // try to copy the node
    var newAjax = myQuickPosts[myQuickPosts.length-1].cloneNode(true);
    // add the copied node to the body itself
    document.body.appendChild(newAjax);
    
    // set specific values depending on the return from the xmlHttpRequest object
    // I'm using -2 because:
    // A) The array starts at 0
    // B) I want to fill the second last one, as the copied one will have a display style of none
    myQuickPosts[myQuickPosts.length-2].style.display = "";
    myEditButtons[myEditButtons.length-2].href += cPostId;
    myQuoteButtons[myQuoteButtons.length-2].href += cPostId;
    myPostIds[myPostIds.length-2].href += cPostId;
    myPostTexts[myPostTexts.length-2].innerHTML = cPostText;
    myPostTitles[myPostTitles.length-2].innerHTML = "<b>" + document.getElementById("txtTitle").value + "</b>";
    Now in FireFox, Opera, etc... myQuickPosts.length will return the number of items with the same name. (If I have 10, it will return 10), but in IE it ALWAYS returns 0.

    Am I doing something wrong, or is this a known issue with a known workaround?

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: DOM differences between IE and everything else

    Well IE does not handle quite well the getElementsByName() method, thus you better use getElementsByTagName() and the elements's indexes instead
    http://www.webdeveloper.com/forum/ar...p/t-53696.html

    I really recomend you have a look at JQuery or a similar Javascript language, it will save so much hassle with issues like this

    Hope this helps

  3. #3

  4. #4
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: DOM differences between IE and everything else

    Yea JQuery will blow your mind, makes the simple Javascript stuff work like dream, Just shout if you need any help.

  5. #5

    Thread Starter
    Hyperactive Member BillGeek's Avatar
    Join Date
    Jun 2006
    Location
    Canada
    Posts
    440

    Re: DOM differences between IE and everything else

    Will do. Are you using JQuery at the moment? I'm still trying the first suggestion (getElementsByTagName) but will try using JQuery once I understand just how it works.

  6. #6
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: DOM differences between IE and everything else

    Yea I have been using JQuery for about 6 Months. I would'nt ever use Javascript again as Jquery just makes life so simple!

    Pino

  7. #7

Posting Permissions

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



Click Here to Expand Forum to Full Width