There are several problems I can see here:
1. nulls. I would suggest you do not use NULLS to mean false. A
logical field should be 0 (false) or 1 (true). Set up the DB so the
field has a default value of either of them as you prefer.
2. Your checkboxes have no value even if they are passed as true,
should be eg <input type="checkbox" name="Onboard" value="1">
3. You do not need to use the # hashes around variables inside the cfif
block: <cfif Onboard EQ "")>unchecked</cfif>
4. I think the default state of a checkbox is unchecked, thus you
should positively check them (not uncheck them) thus: <input
type="checkbox" name="Onboard" value="1" <cfif Onboard EQ
1>CHECKED</cfif>>
5. You are providing no differentiation between different records, ie
you are returning lots of form.vars named "onboard", or probably a
single one as a comma delimited list. Either way there is no connection
between the var and the record it belongs to. I expect there are a
number of ways to deal with this, but I do it by concantenating the
input field name thus: <input type="checkbox"
name="Onboard_#EmpID_Muster#" value="1" <cfif Onboard EQ
1>CHECKED</cfif>>. I then provide a list of the keys we are referring
to in a hidden field at the end of the form, thus:
<CFSET tmpkeylist = "">
<cfoutput query="Recordset1">
<CFSET tmpkeylist = listappend(tmpkeylist,EmpID_Muster)>
<input type="checkbox" name="Onboard_#EmpID_Muster#" value="1" <cfif
Onboard EQ 1>CHECKED</cfif>>
---- other query output ----
</cfoutput>
<CFOUTPUT><INPUT TYPE="hidden" NAME="EmpID_Muster_list"
VALUE="#tmpkeylist#"></CFOUTPUT>
</FORM>
6. Unchecked checkboxes return nothing, not even the variable name, so
you must be prepared to create them and give them a false value if they
don't exist. This is what CFPARAM is for. Your update script, looping
thru each EmpID_Muster would thus look something like this:
<CFLOOP LIST="#form.EmpID_Muster_list#" INDEX = "idx">
<CFPARAM NAME = "Onboard_#idx#" DEFAULT = "0">
<cfquery datasource="Muster_Test">
UPDATE dbo.muster
SET Onboard= #evalute("Onboard_#idx#")#
WHERE EmpID_Muster = #idx#
</cfquery>
</CFLOOP>
note the evaluate() which gets the value of the variable
HTH
"Hawkes, Keith A CIV" wrote:
>
> >Date: Tue, 22 Oct 2002 11:31:57 +0100
> >From: Adrian Lynch <[EMAIL PROTECTED]>
> >Subject: RE: Newbie Question on Looping
> >Message-ID:
> <[EMAIL PROTECTED]>
> >
> >Your code, we neeeeeeeed ya code
>
> My apologies, I thought that might have been presumptuous - there I go
> thinking again!
>
> Here it is:
>
> <cfset CurrentPage=GetFileFromPath(GetTemplatePath())>
> <cfif IsDefined("FORM.MM_UpdateRecord") AND FORM.MM_UpdateRecord EQ "form2">
> <cfquery datasource="Muster_Test">
> UPDATE dbo.muster SET
> Onboard=
> <cfif IsDefined("FORM.Onboard")>
> 1
> <cfelse>
> NULL
> </cfif>
> , DayOff=
> <cfif IsDefined("FORM.DayOff")>
> 1
> <cfelse>
> NULL
> </cfif>
> , Liberty=
> <cfif IsDefined("FORM.Liberty")>
> 1
> <cfelse>
> NULL
> </cfif>
> , Leave=
> <cfif IsDefined("FORM.Leave")>
> 1
> <cfelse>
> NULL
> </cfif>
> , TAD=
> <cfif IsDefined("FORM.TAD")>
> 1
> <cfelse>
> NULL
> </cfif>
> , SIQ=
> <cfif IsDefined("FORM.SIQ")>
> 1
> <cfelse>
> NULL
> </cfif>
> WHERE EmpID_Muster=#FORM.EmpID_Muster#
> </cfquery>
> </cfif>
> <cfquery name="Recordset1" datasource="Muster_Test">
> SELECT dbo.muster.EmpID_Muster, dbo.muster.LNAME, dbo.muster.FNAME,
> dbo.muster.RANK,
> dbo.muster.Onboard, dbo.muster.DayOff, dbo.muster.Liberty, dbo.muster.Leave,
> dbo.muster.TAD,
> dbo.muster.SIQ FROM dbo.muster where date_today > getdate()-1 and dept_name
> like 'a%'
>
> </cfquery>
>
> <form name="form1" method="post" action="">
> </form>
> <form method="post" name="form2"
> action="<cfoutput>#CurrentPage#</cfoutput>">
> <table width="852" height="85" border="1" align="center" cellpadding="1">
> <cfoutput query="Recordset1">
> <tr valign="baseline">
> <td height="20" colspan="2" align="right" nowrap>
> <div align="right"><font color="##000000"
> size="2">#Recordset1.RANK# #Recordset1.FNAME#
> #Recordset1.LNAME#___________________ Onboard:_
> <input type="checkbox" name="Onboard" value="" <cfif
> (#Recordset1.Onboard# EQ "")>unchecked</cfif>>
> DayOff:_
> <input type="checkbox" name="DayOff" value="" <cfif
> (#Recordset1.DayOff# EQ "")>unchecked</cfif>>
> Liberty:_
> <input type="checkbox" name="Liberty" value="" <cfif
> (#Recordset1.Liberty# EQ "")>unchecked</cfif>>
> Leave:_
> <input type="checkbox" name="Leave" value="" <cfif
> (#Recordset1.Leave# EQ "")>unchecked</cfif>>
> TAD:_
> <input type="checkbox" name="TAD" value="" <cfif
> (#Recordset1.TAD# EQ "")>unchecked</cfif>>
> SIQ:_
> <input type="checkbox" name="SIQ" value="" <cfif
> (#Recordset1.SIQ# EQ "")>unchecked</cfif>>
> </font> </div></td>
> </tr>
> </cfoutput>
> <tr valign="baseline">
> <td height="20" colspan="2" align="right" nowrap>
> <div align="center">
> <input name="submit" type="submit" value="Update Record">
> </div></td>
> </tr>
> </table>
> <input type="hidden" name="MM_UpdateRecord" value="form2">
> <input type="hidden" name="EmpID_Muster"
> value="<cfoutput>#Recordset1.EmpID_Muster#</cfoutput>">
> </form>
> <p> </p>
--
Regards;
Richard Meredith-Hardy
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Signup for the Fusion Authority news alert and keep up with the latest news in
ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm