ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old April 12th, 2005, 03:08 PM
jbird4k jbird4k is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Location: Maryland
Posts: 54 jbird4k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 40 m 18 sec
Reputation Power: 7
Send a message via ICQ to jbird4k Send a message via Yahoo to jbird4k
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

Reply With Quote
  #2  
Old April 12th, 2005, 03:29 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,627 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 10 h 8 m 55 sec
Reputation Power: 53
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

Reply With Quote
  #3  
Old April 13th, 2005, 10:23 AM
jbird4k jbird4k is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Location: Maryland
Posts: 54 jbird4k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 40 m 18 sec
Reputation Power: 7
Send a message via ICQ to jbird4k Send a message via Yahoo to jbird4k
Kiteless,

Thanks for you input. I have a scenario to try.

tia

Reply With Quote
  #4  
Old April 13th, 2005, 02:57 PM
jbird4k jbird4k is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Location: Maryland
Posts: 54 jbird4k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 40 m 18 sec
Reputation Power: 7
Send a message via ICQ to jbird4k Send a message via Yahoo to jbird4k
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?

Reply With Quote
  #5  
Old April 13th, 2005, 03:21 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,627 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 10 h 8 m 55 sec
Reputation Power: 53
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?

Reply With Quote
  #6  
Old April 13th, 2005, 03:57 PM
jbird4k jbird4k is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Location: Maryland
Posts: 54 jbird4k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 40 m 18 sec
Reputation Power: 7
Send a message via ICQ to jbird4k Send a message via Yahoo to jbird4k
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.

Reply With Quote
  #7  
Old April 13th, 2005, 05:32 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,627 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 10 h 8 m 55 sec
Reputation Power: 53
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?

Reply With Quote
  #8  
Old April 14th, 2005, 09:22 AM
jbird4k jbird4k is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Location: Maryland
Posts: 54 jbird4k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 40 m 18 sec
Reputation Power: 7
Send a message via ICQ to jbird4k Send a message via Yahoo to jbird4k
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:
"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."


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 ??

Reply With Quote
  #9  
Old April 14th, 2005, 09:48 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,627 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 10 h 8 m 55 sec
Reputation Power: 53
Any chance there might be an extra space or something in there? Maybe try this:

<cfif trim( form.submit ) eq "New" >

Reply With Quote
  #10  
Old April 14th, 2005, 10:36 AM
jbird4k jbird4k is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Location: Maryland
Posts: 54 jbird4k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 40 m 18 sec
Reputation Power: 7
Send a message via ICQ to jbird4k Send a message via Yahoo to jbird4k
Trim() did the trick.

Kiteless, thank you for all of time and help, this thing is now working the way I expected.

Thanks again.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Dyamically adding input field to a form


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway