• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

dynamically added form inputs not being passed

Explorer ,
Aug 12, 2008 Aug 12, 2008

Copy link to clipboard

Copied

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?
TOPICS
Advanced techniques

Views

366

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 12, 2008 Aug 12, 2008

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 12, 2008 Aug 12, 2008

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 20, 2008 Aug 20, 2008

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 22, 2008 Aug 22, 2008

Copy link to clipboard

Copied

LATEST
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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation