Skip to main content
Inspiring
August 13, 2008
Question

dynamically added form inputs not being passed

  • August 13, 2008
  • 4 replies
  • 519 views
Hey all,
I have a form that dynamically adds more text inputs as the last input is filled using javascript. The form works fine and if i output the HTML before it submits i see the inputs. But if i dump the forms struct on the action page, the added iputs are not passed. Why is this?
This topic has been closed for replies.

4 replies

djc11Author
Inspiring
August 22, 2008
I'm an idiot. I was creating an id for these elements, but not a name. I added that and it's working fine now. Thank you.
Inspiring
August 21, 2008
you could add the additional field right away and keep the hidden until a button is clicked:

<cfset number_of_fields= 15>

<cfoutput>
<cfloop index="x" from="1" to="#number_of_fields#">

<cfif x IS 1>
<cfset style= "display:block;">
<cfelse>
<cfset style= "display:none;">
</cfif>

<div id="field#x#" style="#style#">
<input type="File" name="field#x#"><br>
</div>
</cfloop>
</cfoutput>

<input type="Button" id="btn_add" onclick="visible_add('field')" value="Add File">

<script language="JavaScript">
function visible_add(id){
var counter= 1;

do{
obj= document.getElementById(id + counter);
if ( obj.style.display == 'none') {
obj.style.display= 'inline';
return;
}
counter++;
}while ( document.getElementById(id + counter) != null )

document.getElementById('btn_add').style.display = 'none';
}
</script>
djc11Author
Inspiring
August 13, 2008
Tested on FF3 and IE7.
I am using jquery append() to add the input to a div in the form.
As I am writing this I realize i maybe should be appending the input fields to the form itself. Even thought when i check the HTML before submission, the inputs are in between the opening/closing form tags, maybe they are just free floating inputs not associated with the form. Hmm. If this is the problem I wonder how i can fix this.

Any other ideas on what the problem is?

*EDIT* Neither browser worked
Participating Frequently
August 13, 2008
how are you adding the additional text input fields?
what browsers have you tested on and received this behavior?
Have any of the browsers you've tested on worked?