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.
var element = document.getElementsByName("element")[0];
Here is a crude code doing the same. I have tested it in both IE8 and Firefox.
<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>