Click here to Skip to main content
15,908,675 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

When i am running my Web Application, in some pages it is giving an Exception as htmlfile invalid argument and it is showing a error in js file in the code as mentioned here

XML
appendElementToFormOrBody: function(element) {
        /// <summary>
        /// Tries to append an element to the current form. If no form exists, the element will be appended to the body element.
        /// </summary>
        /// <param name="element" type="Object">The element to append.</param>
        if (document.forms && document.forms[0]) {
            document.forms[0].appendChild(element);
        } else {
            document.body.appendChild(element);
        }
    }

----------------------------------------------------------------------------
I need help in this issue..
Posted

1 solution

I think the element variable is not declared/initialized properly with a HTML DOM object. Only HTML DOM objects can be passed in to the appendChild method.

I think if you do like below, it will work.
JavaScript
var element = document.getElementsByName("element")[0]; 


Here is a crude code doing the same. I have tested it in both IE8 and Firefox.

HTML
<html>
<head>
</head>
<script>
function myFunction() {
	var myElem = document.getElementsByName("testElem")[0];
	myElem.value += "test ";
	var p = document.createElement("p");
	p.innerHTML = "test test test"
	if (document.forms && document.forms[0]) {
	   document.forms[0].appendChild(myElem);
	   document.forms[0].appendChild(p);
	} 
	else {
	   document.body.appendChild(myElem);
	   document.body.appendChild(p);
	}
}
</script>
<body>
<form name="myForm">
<input type="text" name="testElem" />
test
</form>
</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900