SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru Dashman's Avatar
    Join Date
    Jan 2006
    Location
    Manchester, UK
    Posts
    627
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    insertBefore and IE

    Hi guys ...

    I have the following JS code:

    Code:
    function buildElement(theLabel,name,msg)
    {
        killElement('p_source','details');
        var parent = document.getElementById('p_source');
        
        var newPara     = document.createElement('p');
        newPara.id         = "details";
        var newLabel     = document.createElement('label');
        var newText     = document.createTextNode(msg);
        newLabel.appendChild(newText);
        newPara.appendChild(newLabel);
        
        var newInput     = document.createElement('input');    
        newInput.id     = "source_details";
        newInput.name     = "source_details";
        newInput.className     = "text";        
    
        newPara.appendChild(newInput);
        
        insertAfter(parent, newPara, theLabel);
    }
    Basically, it builds a new paragraph, along with a lable and text input field, the calls the insertAfter function to insert it into the document.

    The insert after function I am using is as follows:

    Code:
    function insertAfter(parent, node, referenceNode) {
        parent.insertBefore(node, referenceNode.nextSibling);
    }
    Everything works fine in Safari (Mac) and Firefox but it fails in IE 6 and Ie 7.

    The oh-so helpful error messages i get from IE, tells me the following:
    Line: 271
    Char: 2
    Error: Invaild Argument
    Code: 0
    Now, looking at that, line 271 in my script would be the closing brace of the insertAfter function.

    Does anybody know what could be causing this? Like I say, FF's error console and Firebug are not throwing up any errors.

    Cheers,
    D

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    would it be possible for you to post an url so we can see it? If not, use IE's Script Debugger to debug javascript.

    http://www.jonathanboutelle.com/mt/a...debug_jav.html


  3. #3
    SitePoint Guru Dashman's Avatar
    Join Date
    Jan 2006
    Location
    Manchester, UK
    Posts
    627
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi ... thaks for the reply.
    There is an example here: http://www.iamdash.net/dropdowns/drop.html
    Try and select "Estate Agent" or "Exhibition" and you will see the error appear

    D

  4. #4
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the parameter "theLabel" is actually a string and doesn't have the nextSibling property. But whats worse is parent and theLabel are actually both the same thing .



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
  •