lang="en-US"> Internet Explorer FIX: Unknown Runtime Error Using innerHTML & Ajax –  Design1online.com, LLC

Internet Explorer FIX: Unknown Runtime Error Using innerHTML & Ajax

I found that if you’re calling an ajax request that sets an innerHTML value you sometimes get an unknown runtime error  in Internet Explorer. Of course everything works fine in Firefox (why isn’t Microsoft out of business yet?).

Causes:

  1. Improperly nested or missing tags in the value you’re trying to set to innerHTML. This includes things like:
    • lists of <li> with no outer <ul> or <ol> specified
    • <p> tags that aren’t nested properly
    • missing a closing tag like <h1> without matching </h1>
  2. Form tags nested within other form tags

Solutions:

  1. Fix nested tags, or try using <div> tags instead
  2. Remove nested <form> tags

This solution is courtesy of Pieces of Frakesh and other respective comment contributors 🙂

You may also like...

23 Responses

  1. lola says:

    thank you ever so much and God bless you! been trying to get rid of the runtime error in ie for the past 6hrs – i just removed the form tags from my page and voila!

  2. Stewart says:

    Thanks for posting this – that error was getting on my nerves!! Thanks to this post I have put this problem behind me and learned something new – thank you again!!!

    And – I have no idea why Microsoft is still in business! IE is a pain, yet the most used (shouldn’t say popular!) browser out there. Manufacturers like Dell should probably have FF, Safari or Chrome installed on their new computers and set anything but IE to the default – except I’m sure Microsoft would pull some strings to prevent that.. oh well.

  3. G.E.B says:

    Not for me 🙁 I’ve cleaned my code, but this doesn’t help.

  4. Jefim says:

    Thank you.
    Saved me a lot of time!

  5. ghiboz says:

    thankyou!
    I had a problem like this in my website, and after a day trying some solution, I found this…
    tanks!

  6. Luciano says:

    Hey guys,

    i had a problem like this, but, was setting innerHTML inside a <a> element, and no tags left opened, but still get this error.

    Ive just figured out that IE re-validates the whole parent html, ie:

    <div>
    <p>
    <div>
    <a id=”newContent”>Old</a>
    </div>
    </p>
    </div>

    Will throw the error because the tag cant parent a tag, but i dont even touch it.

    Just adding, lookup for your whole html, dont lay your eyes in the changing tag.

  7. musmanjaved says:

    hi buddys, may this help someone.

    case scenario:

    Javascript unknown runtime error in IE while accessing Div inside Div to add ajax contents.

    solution:

    dont ever place nested divs in between the form tags to play with there contents .. 🙂

  8. Eduardo says:

    I NEED the form tag….. what can I do ????? o.O

    • Jade says:

      This doesn’t mean you have to remove all form tags. It means you have TWO form tags, one inside of the other, and you need to get rid of ONE of them.

  9. nkasieng Safi Male malete says:

    My problem was [tags that aren’t nested properly]
    Awesome article,

    Happy coding.

  10. Thank you so much……God Bless you.. I lost my valuable 2 hrs to fix..

  11. Marcel says:

    This has also been driving me crazy. I thought the broblem is so exotic that I wouldnt be able to find anything about it online. Should’ve looked earlier!

    In my case, the runtime error was thrown every time new ajax content included an A tag. I swear there was nothing invalid going on, A within A or anything. But the A tag broke it.

    To fix it, I got rid of the A tags and replaced them with javascript onclick events for divs instead.

    Go to h**l Microsoft. Web programmers should form an alliance and have an MSIE blackout day web wide =o).

  12. Nitin says:

    Thanks a lot.
    My problem was also the nested tags.
    Lookup for your whole html, dont focus on the changing tag only.

  13. Dom says:

    We had a developer who added the ‘id’ attribute to the tag and was then referencing that node in javascript to set the innerHTML. This caused IE7/8 to choke, which is correct behavior here since it is invalid HTML. The other browsers are more forgiving. Use document.title instead.

  14. Padmaja says:

    Hi all i had a problem like this means facebook buttons are not appearing in Firefox,IE and Opera.but i can see only in chrome.Can u please suggestany resolution to fix that. i have checked my code and replaced div tag.but still these are not uploaded

    • Jade says:

      Make sure you don’t have nested form tags. I use facebook buttons on my websites and it’s never caused a problem for me so you probably have a nested form tag somewhere.

  15. Padmaja says:

    Hi buddy,

    i have problem,if i select variants of my product facebook buttons are disappeared
    http://www.pitico.com/de/Maenner/Basic-Shirts/V-Shirt-in-Coral.html
    and if i select variants and click add to cart then the facebook buttons are again appeared
    and facebook js is developed from this document http://www.hyperarts.com/blog/tutorial-how-to-add-facebook-share-button-to-your-web-site-pages/
    i have enable.tpl(for facebook buttons ) and selectbox.tpl(for variant dropdown ).can u please help me how to fix this.

    • Jade says:

      Why are you using ajax to re-load so much of the page? That’s the problem. You should set an ID or a class on the sections you want to re-load and leave the social div untouched. Every time you’re doing an ajax call the facebook buttons aren’t smart enough to initialize again. You could also try re-initializing them manually after the ajax call returns a response.

  16. prasanna says:

    cheers saved me a lot of time

  17. Prerana says:

    I have a checkbox, whose id im not bale to get using innerHTML fter 1st postback…. When the page loads it has value as [objectHTMLInputElement] but when it is post back, the value becomes [object] & i get error as microsoft jscript runtime error unknown runtime error innerhtml……
    I do not have any nested form tags…plz suggest suitable solution

    • Jade says:

      Make sure you don’t have any nested form tags and that you have a closing tag for all of your tags inside of your form tags.

  18. Dri says:

    Thank you SO much!! I just removed the tags from my page and it worked! =D

Leave a Reply to Jade Cancel reply