468,505 Members | 1,785 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

Problem with IE's innerHTML and <form> tags??!?!

I'm having a really hard time with IE's innerHTML property and <form>
tags. If I use this code:

myDiv.innerHTML = "<form>This is a test</form>" in fireFox, the div tag
shows the content. However, if I do the same in IE, nothing happens.
For whatever reason, IE will not take that content.

Has anybody run into this, and what's a good solution? (Please, no "use
FireFox!" answers - we have users that use both equally).

Thanks for any help.

Feb 15 '06 #1
3 3389


Nebulus wrote:
I'm having a really hard time with IE's innerHTML property and <form>
tags. If I use this code:

myDiv.innerHTML = "<form>This is a test</form>" in fireFox, the div tag
shows the content. However, if I do the same in IE, nothing happens.


Complete example

var div = document.createElement('div');
div.id = 'div1';
div.innerHTML = '<form>Kibology for all.</form>';
document.body.appendChild(div);
alert(div.outerHTML);

works fine for me with IE 6 on Windows XP, the div is rendered and the
outerHTML looks correct.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 15 '06 #2
Thanks for the help. I tested with some basic HTML/JS and was able to
put anything I wanted into the DIV tag.

However, I'm using a page that has a more complex layout and it also
uses some flash. When I try to add a form to a DIV in that page using
this exact code:

objDiv = document.getElementById('testDiv');
objDiv.innerHTML = '<form id="testForm" name="testForm"
method="GET">Test Form</form>';

then I get an unknown runtime error. Any ideas?

Feb 15 '06 #3
Um, nevermind.... I FINALLY figured it out. I had this code:

<form>
....inputs here...
<div id="testDiv">my test div here</div>
</form>

Obviously, you can't nest forms. Once I pulled the DIV out of the form,
it worked. DUH!

Feb 15 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Phlip | last post: by
2 posts views Thread by Larry | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.