473,395 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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>

May 23 '07 #1
1 5961
On May 24, 9:40 am, Derek Basch <dba...@yahoo.comwrote:
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.
I don't know what your problem was since you didn't post the non-
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 ... >
<div>
<!-- the rest of the form -->
</div>
</form>
The div can be replaced with a p or table element, or any block
element.

<URL: http://www.w3.org/TR/html401/interac...html#edef-FORM >
[...]
<form name="form1" action="test.php">
<div id="hiddenList"></div>

<input type="submit" onClick="addInput()">
It's not a good idea to combine a submit button with an onclick event,
use the form's onsubmit handler instead.
--
Rob

May 24 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: daveland | last post by:
I am working on some JavaScript that dynamically adds rows to a table in response to a button click. A new row does appear on the screen when the button is clicked. However, that table to which a...
7
by: pizzy | last post by:
PROBLEM: I CAN'T GET THE LAST RESUTS TO WORK CORRECTLY. I WOULD PROVIDE THE CODE (AND WILL IF REQUESTED). BUT IN MY OWN WORDS I AM TRYING TO HAVE THE FIRST FORM DYNAMICALLY CREATE INPUT BOXES...
6
by: hsomob1999 | last post by:
so i have a <ul> and I allow the user to append items to it. The problem is that on mozilla the <span class="line"> which is just a line to divide the sections gets overlaped and doesnt move down...
7
by: JavaScriptRocks | last post by:
I've been trying to imitate / reverse engineer the add attachment feature in gmail composer. I managed to do it to say about 80% but its giving me trouble in IE on WinXP-Sp2. I am using PHP to do...
3
by: IRAS Blues | last post by:
Hi all, I've got a form that consists of a bunch of textboxes and also file upload inputs. For both sets of fields, I need to be able to add in additional elements on the fly. This is done by an...
1
by: bumpy | last post by:
I wrote this pretty slick DHTML table that lets you add/remove rows and show/hide columns on the fly. It works perfectly in IE7, but it doesn't behave in Firefox 2.0.0.4. You can see it in action...
0
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options...
6
by: azegurb | last post by:
Hello, I have one question again i created one table again and in this table i added some another options for ex at the previous table there were only one problem sum of the dynamically added...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.