On May 24, 9:40 am, Derek Basch <email@example.com> wrote:
> I spent several hours struggling with dynamic form fields added with I don't know what your problem was since you didn't post the non-
> 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.
working code, I suspect it was as a result of putting DOM-altering
code in an onclick handler on the submit button - use the form's
onsubmit event instead.
In any case, your code works fine even if you remove the div and
append the input to the form from the submit button's click event.
For the record, to be valid HTML a form must have a block element
inside it enclosing all the form controls, like:
<form ... >
<!-- the rest of the form -->
The div can be replaced with a p or table element, or any block
<URL: http://www.w3.org/TR/html401/interact/forms.html#edef-FORM >
It's not a good idea to combine a submit button with an onclick event,
> <form name="form1" action="test.php">
> <div id="hiddenList"></div>
> <input type="submit" onClick="addInput()">
use the form's onsubmit handler instead.