« Free Scrum Process Guidance for VSTS | Main | Vogels, Scalability, Testing »

2006.03.28

innerHTML and non-block elements

I ran into an interesting [read: really frustrating] IE issue today. If you have a non-block element, e.g. a form, and you try to insert content using innerHTML, e.g.

form.innerHTML += '<input type="hidden" name="a" value="b" />'

You may get an error along the lines of "Unknown runtime error" (hresult: -2146827687). The short answer is that form is a non-block element and you cannot insert a block element inside a non-block element. Interestingly, this has been working for me for for the past two months. I haven't figured out what changed yet to push it over the edge.

So, the fix for me was relatively straight-forward. I already had a div nested inside the form, and so I just grabbed it, prototype-style:

$('left-form').innerHTML += '<input type="hidden" name="a" value="b" />'

form.submit();

And everything was cool again.

Ahhhh, minutiae, how I love thee.

I found the right direction from this forum, so um, mad, um, er, props. Or whatever the cool kids say.

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d83451806669e200d834b55d6669e2

Listed below are links to weblogs that reference innerHTML and non-block elements:

» MonoRail #4: Validation from J.D. Meridth
This post was decided upon after watching Hammet s screencast on using attribute-based validation [Read More]

Comments

hi there. so i didnt understand any of that..and you are pretty smart. haha. lol well love yoou!!!! xxoo britt
hey! so i can't reply to your email and...I don't know why..heh..lol. Anyways, I am sooo ready for school to be out!! High School is so over-rated...lol. anyways, uhm..are you guys goin to alex's birthday party? how was Minnesota? okay well im technically not suppost to be doing this being that I am at school, so ill ttyl!! love you!! xxoo
Saved my day. Thanks!
Thank you. Saved my contact form while using validation in Castle MonoRail.

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Comments are moderated, and will not appear until the author has approved them.

November 2008

Sun Mon Tue Wed Thu Fri Sat
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            
Blog powered by TypePad

We Like