[thelist] DIV InnerHTML,JavaScript, and Forms...

Peter-Paul Koch gassinaumasis at hotmail.com
Mon Jun 3 07:32:00 CDT 2002


>Hey everyone, here is a stumper (for me anyhow...).  I am working on a
>form, that contains <div> areas that are not visible to start with (ex:
><div id=²butter²>&nbsp;</div> ).  When a user chooses the correct button,
>etc, a .js function replaces the blank area with a form field via innerHTML
>(ex:

>Function changeMe(){
>Document.all.butter.innerHTML = ³form field html here = Œstuff¹ and more
>html²
>}
>
>Now, I know that innerHTML is a bastard in Netscape, which I really don¹t
>need to address.  The problem is, the form shows up and works great, but I
>cannot capture the form elements in this <div> when I submit the form.   I
>can only guess this is because they really don¹t exist on the page...
>
>Any one have a solution or thoughts?

It's because when you change the innerHTML of an element, the revised DOM
tree (document.all.b.etc) isn't immediately available. The browser needs a
little while (during which no JavaScript may be executed) to parse the new
innerHTML and create a new part of the DOM tree.

Solution: change the innerHTML, set a timeout of about half a second, then
call a new function that accesses the form through the normal DOM.

ppk

_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com




More information about the thelist mailing list