Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting/Unsetting checkboxes 1

Status
Not open for further replies.

davejoyce

Programmer
Jun 26, 2000
29
US
I am trying to set and unset a value in a database based on the value of a field the user has checked. I am able to set the field in the database but when the user unchecks, the field in the database remains the same. Any Ideas?? Attached is code snippet.<br><br><br>----&nbsp;&nbsp;personnel4.cfm&nbsp;&nbsp;-----<br><br>&lt;CFIF IsDefined(&quot;ID&quot;)&gt;<br> &lt;CFSET NewRecord=&quot;No&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&lt;CFELSE&gt;<br>&nbsp;&nbsp;&nbsp; &lt;CFSET NewRecord=&quot;Yes&quot;&gt; <br>&lt;/cfif&gt;<br><br>&lt;CFIF NewRecord&gt;<br> &lt;CFSET PageTitle = &quot;Add Personnel&quot;&gt;<br> &lt;CFSET ButtonText = &quot;Add Personnel&quot;&gt;<br> &lt;CFSET Last_Name = &quot;&quot;&gt;<br> &lt;CFSET BroadcastNotify = &quot;&quot;&gt;<br> &lt;CFELSE&gt;<br>&nbsp;&lt;CFQUERY DATASOURCE=&quot;AFSMtest_Sites&quot; Name=&quot;Personnel&quot;&gt;<br>SELECT&nbsp;&nbsp;ID,<br> Last_Name ,<br> BroadcastNotify <br> FROM personel_tbl<br>WHERE ID=#ID#<br>&lt;/cfquery&gt;<br> &lt;CFSET PageTitle= &quot;Update Personnel-&quot; &gt; <br> &lt;CFSET ButtonText = &quot;Update Personnel&quot;&gt;<br> &lt;CFSET Last_Name = Trim(Personnel.Last_Name)&gt;<br> &lt;CFSET First_Name = Trim(Personnel.First_Name)&gt;<br><b> &lt;CFSET BroadcastNotify = Personnel.BroadcastNotify&gt;</b><br> <br>&lt;/cfif&gt;<br>&lt;CFOUTPUT&gt;<br><br>&lt;html&gt;<br>&lt;head&gt;<br> &lt;title&gt;#PageTitle#&lt;/title&gt;<br>&lt;/head&gt;<br><br>&lt;body bgcolor=&quot;gray&quot;&gt;<br>&lt;H3&gt;&lt;font color=&quot;White&quot;&gt;#PageTitle#&lt;/font&gt;&lt;/h3&gt;<br><br>&lt;FORM ACTION=&quot;personnel5.cfm&quot; METHOD=&quot;POST&quot;&gt;<br>&lt;CFIF NewRecord IS &quot;No&quot;&gt;<br>&nbsp;&lt;INPUT TYPE=&quot;hidden&quot; NAME=&quot;ID&quot; VALUE=&quot;#ID#&quot;&gt;<br>&lt;/cfif&gt;<br><br>&lt;TABLE BORDER=0 WIDTH=100%&gt;<br>&lt;TR&gt;&lt;TD align=&quot;right&quot; WIDTH=30%&gt;&lt;B&gt;Last_Name:&lt;/b&gt;&lt;/td&gt;&lt;TD align=&quot;Left&quot; WIDTH=70%&gt;&lt;INPUT TYPE=&quot;text&quot; Name=&quot;Last_Name&quot; Size=&quot;50&quot; MAXLENGTH=&quot;50&quot;<br>VALUE=&quot;#Last_Name#&quot;&gt;&lt;/td&gt;&lt;/tr&gt;<br>&lt;tr&gt;&lt;TD align=&quot;right&quot; WIDTH=30%&gt;<br><b>&lt;CFIF #Compare(#BroadcastNotify#,&quot;1&quot;)#&gt;<br>&lt;INPUT TYPE=&quot;checkbox&quot; NAME=&quot;BroadcastNotify&quot; VALUE=&quot;1&quot;&gt;<br>&lt;cfelse&gt;<br>&lt;INPUT TYPE=&quot;checkbox&quot; checked NAME=&quot;BroadcastNotify&quot; VALUE=&quot;1&quot;&gt;<br>&lt;CFSET #BroadcastNotify# = &quot;0&quot;&gt;<br>&lt;/cfif&gt;</b><br>&lt;/td&gt;&lt;TD align=&quot;Left&quot; WIDTH=70%&gt;&lt;B&gt;Notify on Broadcast Message Change?&lt;/b&gt;<br>&lt;/td&gt;&lt;/tr&gt;<br>&lt;/table&gt;<br>&lt;INPUT TYPE=&quot;submit&quot; Value=&quot;#ButtonText#&quot;&gt;<br>&lt;INPUT TYPE=&quot;reset&quot; VALUE=&quot;Clear&quot;&gt;<br><br>&lt;/form&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;<br>&lt;/cfoutput&gt;<br><br><br>---- personnel5.cfm ----<br><br>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;&gt;<br><br>&lt;CFIF IsDefined(&quot;FORM.ID&quot;)&gt;<br><b> &lt;CFUPDATE DATASOURCE=&quot;AFSMtest_Sites&quot; TABLENAME=&quot;Personel_tbl&quot;&gt;</b><br>&nbsp;&nbsp;&lt;CFELSE&gt;<br>&nbsp;&nbsp; &lt;CFINSERT DATASOURCE=&quot;AFSMtest_Sites&quot; TABLENAME=&quot;Personel_tbl&quot;&gt;<br>&lt;/cfif&gt;<br><br><br><br>thanks,<br>&nbsp;&nbsp;Dave Joyce<br><br>&nbsp;&nbsp;
 
I use a quirk in how form variables are passed once the form is submitted: if a checkbox is unchecked it is not passed as a parameter to the receiving form.<br>So, let's say that my checkbox is called frm_chkYN, with accepted values &quot;Y&quot; ana &quot;N&quot;. At hte top of the receiving form I put:<br><br>&lt;cfparam&nbsp;&nbsp;name=&quot;FORM.frm_chkYN&quot; default=&quot;N&quot;&gt;<br><br>and this takes care of the first part of the problem.<br><br><br>After reading the value from the database I have a variable set with the value found in the table<br><br>&lt;cfset VARIABLES.init_chkYN = #QueryName.chkYN#&gt;<br><br>and in the form itself<br><FONT FACE=monospace><br>&lt;cfif VARIABLES.init_chkYN IS &quot;S&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;cfset tChecked=&quot;checked&quot;&gt;<br>&lt;cfelse&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;cfset tChecked=&quot;&quot;&gt;<br>&lt;/cfif&gt;<br><br>&lt;input type=&quot;checkbox&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;name=&quot;frm_chkYN&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;value=&quot;Y&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;#VARIABLES.tChecked#&gt;<br></font><br><br>Note that the form variable is <b>always</b> set the the checked value<br><br>HTH<br><br>
 
silvioc,<br><br>You wrote:<br><br>&quot;if a checkbox is unchecked it is not passed as a parameter to the receiving form.&quot;<br><br>is this a quirk in coldfusion handling. This isn't something you do?<br><br>&nbsp;Your solution worked great. The only thing I don't understand is I don't send the form variable to the receiving form, so I expected the default of N to be picked up always. But it does work as you wrote. <br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thanks,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dave Joyce<br>&nbsp;&nbsp;&nbsp;<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top