Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

checkboxes and coldfusion

Posted on 2008-06-13
4
262 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
System Analysis 5 61
coldfusion, javascript onclick url update 4 61
Stream live video from Raspberry Pi camera 22 191
coldfusion upload spreadsheet into the databse 2 51
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…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

839 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