Dynamic form fields added with appendChild or innerHTML do not POST on submit in Firefox

D

Derek Basch

I spent several hours struggling with dynamic form fields added with
appendChild or innerHTML not POSTing on submit in Firefox. The only
way I found to make it work is to append any created fields to a DIV
within the form. Here is an example I store from another post. I hope
this helps someone.

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<title>creating input elements dynamically</title>
<script type="text/javascript">
function addInput () {
var div;
if (document.getElementById) {
div = document.getElementById('hiddenList');
var input;
if (document.createElement && (input =
document.createElement('input'))) {
input.type = 'hidden';
input.name = 'currentDate';
input.defaultValue = input.value = new Date().toString();
div.appendChild(input);
}
}
}

function showQueryString () {
document.write('<p>location.search: ' + location.search + '<\/p>\r
\n');
}

</script>

</head>
<body>
<script type="text/javascript">
showQueryString();
</script>

<form name="form1" action="test.php">
<div id="hiddenList"></div>

<input type="submit" onClick="addInput()">
</form>

</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top