Question:

Coldfusion and checkbox. checkbox wont go back an forth between true an false

by  |  earlier

0 LIKES UnLike

Ok so let say someone entered information on the 1st page an they click submit (all the information added goes to a database). Then on the second page they see the same information they had typed on the 1st page on the second page. Well they see they made an error and decide to correct it an click update an it tells you, your form has been updated (the changes are made to the database). Anyway all the fields works right except for the checkbox. When i submit the checkbox on the first page i have no problems, it submits correctly. However, when i try to make changes to the checkbox on the second page and click update i have problems. Basically the checkbox will not go back an forth between true an false. Either it remains true, or it remains false.Any suggestions?

Here is whats on my first page

<input type="checkbox" name="htpp" value="1"/>

here is whats on my second page

<cfparam name="Form.htpp" default="0">

<input type="checkbox" name="htpp" id="htpp" value="1"

<cfif #form.htpp# eq "1">checked=yes</cfif>/>

an here is whats on the part of my form that updates the information

<cfparam name="Form.htpp" default="0">

Thanks to all who help,

Rach

 Tags:

   Report

1 ANSWERS


  1. Hello, me again.

    First, check out the source link. It talks about pulling data from databases.

    Second, if you are submitting data to a DB and then displaying it in a form, always display what is in the DB rather than what was in the POST. The practice reduces errors.

    If a logic statement is not working in the manner you would expect, just display the raw data as text before trying to do things based on the results of the data. Do an output to see what the variable is.

    &lt;cfquery datasource = &quot;table&quot; name = &quot;main&quot;&gt;

    SELECT htpp FROM table ORDER BY id DESC LIMIT 1

    &lt;/cfquery&gt;

    &lt;cfoutput query = &quot;main&quot;&gt;#htpp#&lt;/cfoutput&gt;

    Once you know the data that is coming out is what you want:

    &lt;cfoutput query = &quot;main&quot;&gt;

    &lt;cfparam name=&quot;isChecked&quot; default=&quot;&quot;&gt;

    &lt;cfif #htpp# eq &quot;1&quot;&gt;

    &lt;cfset isChecked = &quot; checked&quot;&gt;

    &lt;/cfif&gt;

    &lt;input type=&quot;checkbox&quot; name=&quot;htpp&quot; value=&quot;1&quot;&lt;cfoutput&gt;#isChecked# &lt;/cfoutput&gt; /&gt;

    &lt;/cfoutput&gt;

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.