Skip to main content
April 8, 2010
Question

Dynamically add form fields

  • April 8, 2010
  • 1 reply
  • 909 views

Whats the easiest way to be able to create form fields dynamically? Lets say i have the following code:

<cfform name="test" action="submit.cfm" method="post">

<table>

     <tr>

          <td>Name</td>

          <td>Quantity</td>

     </tr>

     <tr>

          <td><cfinput type="text" name="name1"></td>

          <td><cfinput type="text" name="quant1"></td>

     </tr>

     <tr>

          <td><cfinput type="text" name="name2"></td>

          <td><cfinput type="text" name="quant2"></td>

     </tr>

<tr>

     <td><cfinput type="button" name="addField" value="Add Item"></td>

</tr>

     <tr>

          <td><cfinput type="submit" name"submitForm" value="Submit"></td>

     </tr>

</table>

</cfform>

How would i be ableto use the addField button to add more input fields?

    This topic has been closed for replies.

    1 reply

    ilssac
    Inspiring
    April 8, 2010

    Just so you know, you are asking a JavaScript question on a ColdFusion forum.

    At this time, AFAIK, ColdFusion does not have any functionality to create this JavaScript for you.

    But this is a fairly easy task to do in JavaScript, and I usually find some hand code to do with a simple search.  Such as:

    http://www.google.com/search?q=javascript+add+form+element&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a