checkboxes and coldfusion

I have a number od checkboxes that i am need to insert the completion date into the database. So if the check box is checked insert the todays date into the dataabse for that Employee it was checked . and I am getting the error saying that <cfloop does not have closing tag

My action page is here
<cfif isDefined("form.btnSubmit")>
<cfloop index="variables.i" from="1" to="#ListLen(form.ch)#">
           <cfset variables.thisCheckbox = ListGetAt(form.ch,variables.i)>

           <cftry>
           <cfquery name="insertCompletion" datasource="cfelsunrise" dbtype="ODBC">
                        INsert into EmployeeTraining (CompletionDate,StartDate,EmployeeID,CourseID,CourseName,EnteredBy) values
                        (variables.thisCheckbox,getDate(),#form.employeeID#,1661,'REM JOURN DISC',#session.EmpID#)

            </cfquery>
            <cfcatch type="database">
              There was a database error!
            </cfcatch>
         </cftry>

</cfloop>
<!---<cflocation url="rem_dashboard.cfm" addtoken="no">--->
</cfif>
And the code is here 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
 
<cfquery name="getCareManagers" datasource="cfelsunrise" dbtype="ODBC">
		<!--- Executive Director --->
        select e.employeeid ,e.last_name as lname,e.first_name as fname,ej.JobCode,l.name
		from Employee e
		join EmployeeJobHistory ej			ON ej.EmployeeID = e.EmployeeID
		inner join JobAssignment ja			on ej.sequence = ja.sequence
		inner join location l on ja.locationId=l.locationId
 
		where  ja.EndDate is NULL and l.locationID=#session.Locationid# AND (ej.JobCode = '1001' or ej.JobCode = '1101' or ej.JobCode = '1007')
		order by lname
	</cfquery>
 
 
 
<body>
<form name="frmCheck" action="checkCompletion.cfm" method="post">
<h2 align="center">Reminiscence Training</h2>
<h3 align="center">REM JOURN DISC</h3>
<table width="50%" align="center">
	<tr>
		<th>Name</th>
		<th width="36%">Location</th>
		<th>Job Code</th>
		<th>Section1</th>
		
		
	
	
	</tr>
<cfset lastEmp=''>
 
<cfoutput query="getCareManagers">
<input type="hidden" name="EmployeeID" value="#EmployeeID#" />
<cfif lastEmp is not #EmployeeID#>
	<cfquery name="checkCompletion" datasource="cfelsunrise" dbtype="ODBC">
		select * from EmployeeTraining where EmployeeID=#EmployeeID# and completionDate is not null and courseID=1661
	
	</cfquery>
	
	<tr>
		<td width="39%">#lname#,#fname#(#EmployeeID#)</td>
		<td align="center">#name#</td>
		<td align="center">#jobCode#</td>
		<td align="center" width="25%"><input type="checkbox" name="ch" value="#DateFormat(now(),"mm/dd/yyyy")#"  /></td>
	</tr>
 
<cfset lastEmp=#EmployeeID#>
</cfif>
</cfoutput>
 
<tr>
<td align="left" colspan="1"><cfoutput><strong style="font-size:16px">Total:#getCareManagers.recordcount#</strong></cfoutput></td>
<td align="right" colspan="1"><input type="submit" name="btnSubmit" id="btnSubmit" value="Complete The Course" /></td>
</tr>
</table>
 
<cfoutput>
<input type="hidden" name="counter" value="#getCareManagers.recordcount#">
 
</cfoutput>
</form>
 
</body>
</html>

Open in new window

LVL 19
erikTsomikSystem Architect, CF programmer Asked:
Who is Participating?
 
dgrafxCommented:
it looks like you removed your
<input type="hidden" name="EmployeeID" value="#EmployeeID#" />
from your form
the form field EmployeeID is tested for or an insert won't happen
and why not just add the checkCompletion query to the getCareManagers query???
however you do it you can streamline by doing:
<input type="checkbox" class="green" name="#EmployeeID#" <cfif isDate(checkCompletion.completiondate)>disabled="disabled" checked</cfif>/>

note: you can remove your if isdefined("form.btnsubmit") block
0
 
dgrafxCommented:
first off
one would want to do something like:
<input type="checkbox" name="#EmployeeID#"> instead of name="ch" value="#now()# ..."
and it looks like you want to group so you can remove the empid thing and do
<cfoutput query="getCareManagers" group="EmployeeID">

and on action page
<cfif StructKeyExists(form,"EmployeeID")>
      <cfloop list="#form.EmployeeID#" index="ii">
            <cfif StructKeyExists(form,ii)>
                  <cfquery name="insertCompletion" datasource="cfelsunrise" dbtype="ODBC">
                  insert into EmployeeTraining
                  (CompletionDate,StartDate,EmployeeID,CourseID,CourseName,EnteredBy)
                  values
                  (getDate(),getDate(),#ii#,1661,'REM JOURN DISC',#session.EmpID#)            
                  </cfquery>
                  note: where you are inserting completiondate - on the form you appeared to want to set to now() so why not just set to getDate()? but then one wonders why completion and start are the same ???
            </cfif>
      </cfloop>
</cfif>
0
 
erikTsomikSystem Architect, CF programmer Author Commented:
I try this and it does not insert a record into the dataabse
I change the code to
<cfoutput query="getCareManagers">

<cfif lastEmp is not #EmployeeID#>
      <cfquery name="checkCompletion" datasource="cfelsunrise" dbtype="ODBC">
            select completiondate from EmployeeTraining where EmployeeID=#EmployeeID#  and courseID=1661
      
      </cfquery>
      
      <tr>
            <td width="39%">#lname#,#fname#(#EmployeeID#)</td>
            <td align="center">#name#</td>
            <td align="center">#jobCode#</td>
            <td align="center" width="25%">
      
            <cfif checkCompletion.completiondate neq "">
            <input type="checkbox" name="#EmployeeID#" value="#now()#" checked="checked" disabled="disabled" class="green"/>
            <cfelse>
            <input type="checkbox" name="#EmployeeID#" value="#now()#" />
            </cfif>
            </td>
      </tr>

<cfset lastEmp=#EmployeeID#>
</cfif>
</cfoutput>

And action page to
<cfif isDefined("form.btnSubmit")>
<cfif StructKeyExists(form,"EmployeeID")>
      <cfloop list="#form.EmployeeID#" index="ii">
            <cfif StructKeyExists(form,ii)>
                  <cfquery name="insertCompletion" datasource="cfelsunrise" dbtype="ODBC">
                  insert into EmployeeTraining
                  (CompletionDate,StartDate,EmployeeID,CourseID,CourseName,EnteredBy)
                  values
                  (getDate(),getDate(),#ii#,1661,'REM JOURN DISC',#session.EmpID#)            
                  </cfquery>
                 
            </cfif>
      </cfloop>
     
</cfif>
<cflocation url="rem_dashboard.cfm" addtoken="no">
</cfif>
0
 
erikTsomikSystem Architect, CF programmer Author Commented:
Great job
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.