Results 1 to 8 of 8

Thread: Weird runtime error in IE

  1. #1
    Join Date
    Jul 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Weird runtime error in IE

    Hey I have this one line of javascript that works fine in FF but creates a runtime error in IE, iv gone over it over and over and can't figure out whats causing the runtime error, any help would be great, thx

    Code:
    	var theString = '<br /><div style="border-top:1px solid white;border-bottom:1px solid white;"><br /><textarea id="commentEditor'+target+'" style="width:383px;" onkeyup="commentChanged('+target+');"></textarea><br /><a href="javascript:saveNewComment('+target+');">Save Changes</a> | <a href="javascript:cancelNewComment('+target+');">Cancel</a></div>';
    i narrowed things down a bit to try and figure it out and I have it narrowed down to one tiny part of the string:

    this line of code works fine:
    Code:
    var theString = '<br /><div style="border-top:1px solid white;border-bottom:1px solid white;"><br /><textarea id="commentEditor'+target+'" style="width:383px;" onkeyup="commentChanged('+target+');"></textarea><br />Save Changes</div>';
    but if i add in the <a> tag around save changes IE spits out the runtime error:
    Code:
    var theString = '<br /><div style="border-top:1px solid white;border-bottom:1px solid white;"><br /><textarea id="commentEditor'+target+'" style="width:383px;" onkeyup="commentChanged('+target+');"></textarea><br /><a href="#">Save Changes</a></div>';
    this seems REALY weird to me :S thx in advance for any insight

  2. #2
    Join Date
    Jul 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    How are you using the string?

  3. #3
    Join Date
    Jul 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    setting it as the innerHTML of a div element

  4. #4
    Join Date
    Jul 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    can't help you, sorry.

  5. #5
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    It works for me in IE6. Perhaps the function commentChanged() is bad.

    If it still does not work for you, I have 2 suggestions. The first is to escape all the "/" by making them "\/"

    The second option is to use the DOM methods instead of innerHTML, which is actually the formal way of doing it.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    <title>Test</title>
    </head>
    
    <body>
    <div>
    
    <div id="theDiv">abc</div>
    
    <script type="text/javascript">
    
    var target = "theTarget";
    function commentChanged(foo) {return foo+"bar";}
    
    var p = document.getElementById("theDiv");
    while(p.hasChildNodes()) p.removeChild(p.firstChild);
    
    var d = document.createElement("div");
    d.style.borderTop = "1px solid white";
    d.style.borderBottom = "1px solid white";
    
    var t = document.createElement("textarea");
    t.id = "commentEditor" + target;
    t.style.width = "383px";
    t.onkeyup = "commentChanged(" + target + ");";
    
    var a = document.createElement("a");
    a.href = "#";
    a.appendChild(document.createTextNode("Save Changes"));
    
    d.appendChild(document.createElement("br"));
    d.appendChild(t);
    d.appendChild(document.createElement("br"));
    d.appendChild(a);
    
    p.appendChild(document.createElement("br"));
    p.appendChild(d);
    
    </script>
    
    </div>
    </body>
    </html>
    Trinithis

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    t.onkeyup = "commentChanged(" + target + ");";
    Uh-uh:
    Code:
    t.onkeyup = function() {
      commentChanged(target);
    };
    ... and set
    Code:
    d = t = a = p = null
    at the end to avoid memory leaks in IE.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Jul 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hey guys, I figured it out, but it actualy wasnt a javascript error, just for some reason IE was telling me it was... what actualy was happening is way up in the code there was a </ a> instead of </a> and IE was erroring when it tried to put an anchor inside an anchor... why it was telling me it was a javascript runtime error is beyond me...

    thx for all your help though

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by mortalgos View Post
    Hey guys, I figured it out, but it actualy wasnt a javascript error, just for some reason IE was telling me it was... what actualy was happening is way up in the code there was a </ a> instead of </a> and IE was erroring when it tried to put an anchor inside an anchor... why it was telling me it was a javascript runtime error is beyond me...

    thx for all your help though
    That's the typical IE response to such things.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •