4 Replies Latest reply on Aug 22, 2008 11:11 AM by djc11

    dynamically added form inputs not being passed

    djc11 Level 1
      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?
        • 1. Re: dynamically added form inputs not being passed
          Kronin555 Level 1
          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?
          • 2. dynamically added form inputs not being passed
            djc11 Level 1
            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
            • 3. Re: dynamically added form inputs not being passed
              fober1 Level 1
              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>
              • 4. Re: dynamically added form inputs not being passed
                djc11 Level 1
                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.