Solved

checkboxes and coldfusion

Posted on 2008-06-13
4
260 Views
Last Modified: 2013-12-24
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

0
Comment
Question by:erikTsomik
  • 2
  • 2
4 Comments
 
LVL 25

Expert Comment

by:dgrafx
ID: 21785105
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
 
LVL 19

Author Comment

by:erikTsomik
ID: 21785303
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
 
LVL 25

Accepted Solution

by:
dgrafx earned 500 total points
ID: 21785340
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
 
LVL 19

Author Closing Comment

by:erikTsomik
ID: 31467071
Great job
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now