|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
Dyamically adding input field to a form
I am working on a time recording app and have hit a wall.
I have 3 fields that need to be associated for each staff member: charge Number, Job Code and Hours. At the end of each week the staff member shoudl be able to enter hours for each charge Number and job Code they worked on. If they worked on 4 tasks that could be charged against 4 different charge number and 4 different job codes then they should see 4 rows each containing a drop down for the charge number and job code. Can anyone point me to an example of a form that shows a row of inputs and a means to add additional rows if necessary? Any ideas or pointers would be extremely helpful tia ![]()
__________________
J. Birdsell, ![]() www.carry-on-scheff-fans.com |
|
#2
|
|||
|
|||
|
The easiest way is just to have a button that says "Add another set of fields" that reloads the page and passes a hidden form field or URL variable that tells the page how many additional fields to display. You could also do this with Javascript but it would be more complex (but would not require a page reload).
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
|||
|
|||
|
Kiteless,
Thanks for you input. I have a scenario to try. tia |
|
#4
|
|||
|
|||
|
OK, I have mad e some changes, I get the correct number of records but When I update the record with subsequent loops I get the same value in every record being updated so if my list is mist= 1,2,3,4 and my upddate records have a value 1 for the column being updated.
--------------------------- the data DATE:: 04/14/2005 CatID 2,10,22,30,36 CRID 13,3,6,10,6 HRs 2,4,3,7,20 ------------------------------------ the Code --------------------- Code:
<cfloop list="#form.catID#" index="catID"> <cfquery datasource="#dsn#"> INSERT INTO tblTMDATA(catID, staffID, wkEndingDTD) values (#catID#, #session.staffID#, #session.Date#) </cfquery> </cfloop> <CFLOOP list="#FORM.cr#" index="crID"> <cfquery datasource="#dsn#"> update tblTMDATA Set crID = #crID# Where staffID = #session.staffID# and wkEndingDTD = #Session.date# and crID = 0 </cfquery> </CFLOOP> <CFLOOP list="#FORM.hrs#" index="myHrs"> <cfquery datasource="#dsn#"> update tblTMDATA Set hrs = #myHrs# Where staffID = #session.staffID# and wkEndingDTD = #Session.date# and hrs = 0 </cfquery> </CFLOOP> the DeBug output ----------------------------- SQL = update tblTMDATA Set crID = 13 Where staffID = 9 and wkEndingDTD = 04/14/2005 and crID = 0 (Records=0, Time=0ms) SQL = update tblTMDATA Set crID = 3 Where staffID = 9 and wkEndingDTD = 04/14/2005 and crID = 0 (Records=0, Time=0ms) SQL = update tblTMDATA Set crID = 6 Where staffID = 9 and wkEndingDTD = 04/14/2005 and crID = 0 (Records=0, Time=0ms) SQL = update tblTMDATA Set crID = 10 Where staffID = 9 and wkEndingDTD = 04/14/2005 and crID = 0 (Records=0, Time=0ms) SQL = update tblTMDATA Set crID = 6 Where staffID = 9 and wkEndingDTD = 04/14/2005 and crID = 0 (Records=0, Time=0ms) SQL = update tblTMDATA Set hrs = 2 Where staffID = 9 and wkEndingDTD = 04/14/2005 and hrs = 0 (Records=0, Time=0ms) SQL = update tblTMDATA Set hrs = 4 Where staffID = 9 and wkEndingDTD = 04/14/2005 and hrs = 0 (Records=0, Time=0ms) SQL = update tblTMDATA Set hrs = 3 Where staffID = 9 and wkEndingDTD = 04/14/2005 and hrs = 0 (Records=0, Time=0ms) SQL = update tblTMDATA Set hrs = 7 Where staffID = 9 and wkEndingDTD = 04/14/2005 and hrs = 0 (Records=0, Time=0ms) SQL = update tblTMDATA Set hrs = 20 Where staffID = 9 and wkEndingDTD = 04/14/2005 and hrs = 0 the resulting table values: crID and Hrs should have different values in each row. Code:
tmdID catID crID staffID wkEndingDTD hrs 39 2 13 9 12:00:12 AM 2 40 10 13 9 12:00:12 AM 2 41 22 13 9 12:00:12 AM 2 42 30 13 9 12:00:12 AM 2 43 36 13 9 12:00:12 AM 2 Ideas anyone? |
|
#5
|
|||
|
|||
|
You need to give each form field a unique name...something like #form.catID1#, #form.catID2#, etc. One for each "set" of data the user entered. Make sense?
|
|
#6
|
|||
|
|||
|
It makes sense, but does that mean that I can not use a list to update db records?
this all comes back to, creating new form rows dynamicaly? A record consist of name, date, charge number, job code and hours. for example this week I would have a record for development (this app), Deployment , system reports, and portal maintenance. My coworker usally anywhere from 6 -8 charge numbers per week, May be I am trying to accomplish too much at once. what are your thoughts on this approach. have the initial form, a new button, click new writes the current record to the database, retrieves the record just written from the data base and presents the page back to the user displaying the values of the record and displaying newinput fields. thanks for your help. |
|
#7
|
|||
|
|||
|
Let's say on your form there is a field called catID1. The user can click a button to add additional fields to enter more than one catID. When the second form field is created, it is called catID2. Additional fields are added as catID3 and catID4. You could have a hidden form field that also updates each time the user adds a field. It would start at 1, and as the user adds fields you increment it. So after 4 fields have been added the hidden field (maybe called catIDCount) is set to 4.
Now on the action page you can loop over the catIDCount number and handle each catID. Assuming you use "thisCatID" as your loop index you can get at each value like this: <cfloop index="thisCatID" from="1" to="#form.catIDCount#"> Field name is form.catID#thisCatID# and the value is: #form['catID#thisCatID#']<br> </cfloop> Is that what you're after? |
|
#8
|
|||
|
|||
|
Thank you for you help with this, it's greatly appreicated.
I will give this a try also, meanwhile,I went back to square one, tried the approach I described earlier Quote:
This works fine except when I submit the second time. I have two submit buttons, submit = New and submit = finish. my action page starts with <cfif form.submit eq "NEW' > write the record and return the form <cfelse> write the record say thank you. the second time through <cfif form.submit eq "New" > fails and I get the thank you message even though cf dump show submit = New. Any ideas on why the <cfif > is ignoring the condition on the second pass ?? |
|
#9
|
|||
|
|||
|
Any chance there might be an extra space or something in there? Maybe try this:
<cfif trim( form.submit ) eq "New" > |
|
#10
|
|||
|
|||
|
Trim() did the trick.
Kiteless, thank you for all of time and help, this thing is now working the way I expected. Thanks again. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Dyamically adding input field to a form |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|