Skip to main content
Known Participant
December 7, 2010
Answered

Checkbox not updating

  • December 7, 2010
  • 2 replies
  • 1281 views

I'm running ColdFusion 9 Standard standalone on windows 7. New to Coldfusion - I'm trying to update the value of a check box on a simple update/insert template. The update page is called from a list. All of my other input values show in their respective forms except the checkbox, nor is it updating in the database. Here is the code for the checkbox:

<input type="checkbox" name="reviewed"<cfif #NewRecord# IS "No"><cfoutput query="procs"> value="#reviewed#"</cfoutput></cfif>>

Thanks for your help!

    This topic has been closed for replies.
    Correct answer Dave Watts

    selected="selected"

    should be

    checked="checked"

    Sorry about that.

    Dave Watts, CTO, Fig Leaf Software

    http://www.figleaf.com/

    http://training.figleaf.com/

    Read this before you post:

    http://forums.adobe.com/thread/607238

    2 replies

    Community Expert
    December 7, 2010

    That's not really how checkboxes work - or at least, it's not how they're generally used. You have to change their state (whether the box is checked or not), not their value. So, let's say you have a list of checkbox items populated by one query, then you want one of those to be checked based on another query (the most common use-case for checkboxes).

    <cfquery name="qCheckboxes" ...>

    SELECT RELATED_ID, NAME FROM CHECKBOX_COLUMN

    </cfquery>

    <cfquery name="qMyItem" ...>

    SELECT ITEM_ID, RELATED_ID, ... FROM MYITEMS WHERE ITEM_ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#URL.item_id#">

    </cfquery>

    <cfoutput query="qCheckboxes">

    <input type="checkbox" name="related_id" value="#qCheckboxes.RELATED_ID#"

         <cfif qCheckboxes.RELATED_ID is qMyItem.RELATED_ID>

         selected="selected"

         </cfif>

    /> #qCheckboxes.name# <br/>

    </cfoutput>

    Dave Watts, CTO, Fig Leaf Software

    http://www.figleaf.com/

    http://training.figleaf.com/

    Read this before you post:

    http://forums.adobe.com/thread/607238

    Dave Watts, Eidolon LLC
    Dave WattsCommunity ExpertCorrect answer
    Community Expert
    December 7, 2010

    selected="selected"

    should be

    checked="checked"

    Sorry about that.

    Dave Watts, CTO, Fig Leaf Software

    http://www.figleaf.com/

    http://training.figleaf.com/

    Read this before you post:

    http://forums.adobe.com/thread/607238

    Dave Watts, Eidolon LLC
    _Bryan_Author
    Known Participant
    December 7, 2010

    Thanks Dave. So essentially what you are saying is that I have to create a separate query for a checkbox because coldfusion doesn't know if a field in the database is checked or not?

    tclaremont
    Inspiring
    December 7, 2010

    What is the value of #reviewed#

    Use a CFDUMP or just put #reviewed# on your page to display the current value. My guess is that it is not what you expect it to be.

    Inspiring
    December 7, 2010

    Also, what is the value of NewRecord?

    _Bryan_Author
    Known Participant
    December 7, 2010

    #NewRecord# value should be "no" or unchecked