Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding new rows on page 1

Status
Not open for further replies.

Albert3162

Programmer
Jul 13, 2001
18
US
Hello,

may be somebody done with this:
I need to be able to add a new row to a table on page, when the user clicks an 'add' button. The new row will have the same fields as the first row, but not going to database until user submit this page

Thanks
Albert

 
you'll have to pass the current number of rows to run a loop. then you'll have to do some checks in the form field so populate a value.
Code:
<cfif isdefined("form.submit")>
  do database stuff
</cfif>
<cfparam name = "url.rowCount" default = "1">
<form action="thispage.cfm?rowCount=<cfoutput>#evaluate(url.rowCount + 1)#</cfoutput>>
  <table>
    <cfoutput>
    <cfloop from = "1" to = "url.rowCount" index = "thisRow">
      <tr>
        <td>
          <input type = "text" name = "myFormField#thisRow#" value = "<cfif isdefined("form.myFormField#thisRow#")>#evaluate("myFormField"&thisrow)#</cfif>">
        </td>
      </tr>
    </cfloop>
  </table>
<input type = "submit" value = "submit" name = "submit"> <input type = "submit" value = "add row" name = "addrow">
</form>

if you click add row it will submit the page but since the actual submit button isn't defined it wont add to the db. the form action passes the next row number. each form text field checks to see if there are existing values to repopulate the value.

If you don't ask the right questions, you don't get the right answers. A question asked in the right way often points to its own answer. Asking questions is the ABC of diagnosis. Only the inquiring mind solves problems.

-Quote by Edward Hodnett
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top