Skip to main content
Inspiring
April 9, 2008
Question

Dynamic checkboxes

  • April 9, 2008
  • 2 replies
  • 260 views
I want to dynamically generate checkboxes from a query :

<cfloop query="qryGet_Error">
<cfoutput>
<cfinput type="checkbox" name="error_id" value="#qryGet_Error.error_id#">#qryGet_Error.error#<br>
</cfoutput>
</cfloop>

In the action page, I would have something like this, but how would I setup the select query, based on each checkbox value ?


<cfif isDefined("form.error_id")>
<cfloop list="#form.error_id#" index="error_id_value">
<cfquery name="qry" datasource="datasource">

For example, the query would have to be select if error_id = '1' or error_id = '3' or error_id = '8', etc., based on which checkboxes were selected.

I do not know how to set this up.

<cfelse>
no checkboxes were selected, display message

</cfif>

Thanks
    This topic has been closed for replies.

    2 replies

    Inspiring
    April 9, 2008
    to clarify Dan's post a bit more:

    to select multiple records at once you use WHERE columnname IN
    (comma-delimited list of values) in your query

    thus, you do not need the cfloop at all, since the value of
    form.error_id is already a comma-delimited list.

    your query will look something like:

    SELECT ...
    FROM ...
    WHERE error_id IN (<cfqueryparam cfsqltype="cf_sql_integer" list="yes"
    value="#form.error_id#">)

    assuming error_id is an INT/NUMBER data type. if it is of text-based
    data type, then change cf_sql_integer to cf_sql_varchar.

    hth

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    Inspiring
    April 9, 2008
    where yourfield in (some list)