Uda
Uda

Reputation: 61

Javascript parentNode and innerHTML do not work properly in Firefox

I have a problem when using javascript in Firefox, here is the html:

<HTML>
<BODY>  
        <TABLE align="center">  
            <TR><td><input type=button name=submit onclick="javascript:submitIt()" value="submit" align="center"></td></TR>
            <TD>
                    <TABLE>     
                            <DIV STYLE="display:none position:relative;">   
                                <FORM ID="formA" NAME="formA" METHOD="post" ACTION="b.html" TARGET="_blank">
                                <INPUT TYPE="hidden" NAME=aInput VALUE="1294457296">        
                                </FORM>
                            </DIV>
                </TABLE>
            </TD>
        </TABLE></BODY></HTML>

and here's the javascript:

    <script language="Javascript">
    function submitIt()
{
    oForm = document.getElementById("formA");
    strRequest = "<HTML><BODY>" + oForm.parentNode.innerHTML + "</BODY></HTML>";
    newDoc = window.open("", "", "");
    newDoc.document.write(strRequest);  
}

Problem is when you click submit button in this html page, you'll get a new html with source:

<HTML><BODY><form id="formA" name="formA" method="post" action="b.html" target="_blank"></form>
                                <input name="aInput" value="1294457296" type="hidden">  </BODY></HTML>

but it's supposed to be

<HTML><BODY><form id="formA" name="formA" method="post" action="b.html" target="_blank">
                                <input name="aInput" value="1294457296" type="hidden"></form>   </BODY></HTML>

Could anyone please help please? it will be really appreciated. Thanks!

Upvotes: 0

Views: 5127

Answers (2)

Jonny Buchanan
Jonny Buchanan

Reputation: 62813

It's because your HTML is seriously broken, so the DOM you end up with isn't as expected due to error handling - install Firebug and have a look at the resulting DOM.

Wrapping the <form> in the missing <tr><td>...</td></tr> should give you more like the expected DOM.

Your outer <table> is also missing a <tr> around the second <td>.

Upvotes: 1

soju
soju

Reputation: 25312

parentNode and innerHTML works properly in firefox, your problem comes from your html code which is not valid.

Upvotes: 0

Related Questions