Answered
Assemble and Insert
This may be a lot simpler than I think, but I am drawing a
blank. I am attempting to build a timesheet when an employee can
report their time off per month. Each row consists of a date 2 text
field and 2 selects (2 for hours off and 2 for types).
I need to assemble the rows at the end and insert them into the database so it looks like:
date | hoursoff1 | offtype1 | hoursoff2 | offtype2 | uniqname
I am using a loop based on DaysInMonth to generate the form elements. Any ideas on how I can look and insert each of the rows? I was going to name each form element based on the date, but not sure how to assemble them after for insert. Has to be a better way.
Here is my code so far:
<cfloop from="0" to="#daysInMonth(Now())#" index="i">
<cfset i = i +1>
<table width="400" border="0">
<tr>
<td width="20%"><cfoutput>#thisMonth#/<cfif i LTE 9>0</cfif>#i#/#thisYear#</cfoutput></td>
<td width="20%"><input name="<cfoutput>#thisMonth#/<cfif i LTE 9>0</cfif>#i#/#thisYear#-1</cfoutput>" type="text" id="to1" onBlur="showans()" size="4" maxlength="4"/></td>
<td width="20%">
<select name="codeType1" id="codeType1" onBlur="showans()">
<option value="" selected="selected"></option>
<cfoutput query="codetype" onblur="showans()">
<option value="#ID#">#ID#</option>
</cfoutput>
</select></td>
<td width="20%"><input name="<cfoutput>#thisMonth#/<cfif i LTE 9>0</cfif>#i#/#thisYear#-2</cfoutput>" type="text" id="to2" onBlur="showans()" size="4" maxlength="2" /></td>
<td width="20%"><select name="codeType2" id="codeType2">
<option value="" selected="selected"></option>
<cfoutput query="codeType" onblur="showans()">
<option value="#ID#">#ID#</option>
</cfoutput>
</select></td>
</tr>
</table>
</cfloop>
I need to assemble the rows at the end and insert them into the database so it looks like:
date | hoursoff1 | offtype1 | hoursoff2 | offtype2 | uniqname
I am using a loop based on DaysInMonth to generate the form elements. Any ideas on how I can look and insert each of the rows? I was going to name each form element based on the date, but not sure how to assemble them after for insert. Has to be a better way.
Here is my code so far:
<cfloop from="0" to="#daysInMonth(Now())#" index="i">
<cfset i = i +1>
<table width="400" border="0">
<tr>
<td width="20%"><cfoutput>#thisMonth#/<cfif i LTE 9>0</cfif>#i#/#thisYear#</cfoutput></td>
<td width="20%"><input name="<cfoutput>#thisMonth#/<cfif i LTE 9>0</cfif>#i#/#thisYear#-1</cfoutput>" type="text" id="to1" onBlur="showans()" size="4" maxlength="4"/></td>
<td width="20%">
<select name="codeType1" id="codeType1" onBlur="showans()">
<option value="" selected="selected"></option>
<cfoutput query="codetype" onblur="showans()">
<option value="#ID#">#ID#</option>
</cfoutput>
</select></td>
<td width="20%"><input name="<cfoutput>#thisMonth#/<cfif i LTE 9>0</cfif>#i#/#thisYear#-2</cfoutput>" type="text" id="to2" onBlur="showans()" size="4" maxlength="2" /></td>
<td width="20%"><select name="codeType2" id="codeType2">
<option value="" selected="selected"></option>
<cfoutput query="codeType" onblur="showans()">
<option value="#ID#">#ID#</option>
</cfoutput>
</select></td>
</tr>
</table>
</cfloop>
