13 Replies Latest reply on Aug 15, 2007 8:29 PM by cf_dev2

    checked boxes

    KeithLaw999 Level 1
      howdy,

      can someone help me with a check box issue plz?

      i have i cfoutput of a list of categories from my category_table with check boxes next to them, i have another table CategoryToProduct and a session variable on the page which is the ProductID.

      i want to have the check boxes checked if the productID matches in the CategoryToProduct table.

      i have 2 queries but not sure how to join them to acheive what i need?
        • 1. Re: checked boxes
          Dan Bracuk Level 5
          First, rewrite your queries so that you are pulling category IDs. That's what is generally more useful than names in terms of form values. Plus, your second query could probably be a Q of Q.

          Then, change this:

          <input type="checkbox" name="checkbox"
          value="checkbox"
          checked>

          to this

          <input type="checkbox" name="checkbox"
          value="#SomethingFromYourQuery#"
          <cfif listfind(ValueList(YourSecondQuery.somerow), SomethingFromYourFirstQuery) gt 0>
          checked="checked"
          </cfif>
          >

          • 2. checked boxes
            KeithLaw999 Level 1
            ok thank you, i have changed the queries i think they are more appropriate, slightly different queries to what you surgested, but its not quite working

            any ideas what i need to change?
            • 3. Re: checked boxes
              Dan Bracuk Level 5
              I'm guessing that this
              <cfif listfind(ValueList(get_Selected_Cats.CatID99), get_All_Cats.Cat_ID) gt 0>
              checked="checked"

              should be this
              <cfif listfind(ValueList(get_All_Cats.Cat_ID)get_Selected_Cats.CatID99, ) gt 0>
              checked="checked"
              • 4. Re: checked boxes
                KeithLaw999 Level 1
                ok i have tried that but i get this error?

                Invalid CFML construct found on line 49 at column 46.
                ColdFusion was looking at the following text:
                get_Selected_Cats.CatID99

                The CFML compiler was processing:

                an expression beginning with "listfind", on line 49, column 7.This message is usually caused by a problem in the expressions structure.
                a cfif tag beginning on line 49, column 2.


                The error occurred in D:\httpdocs\EditPartsCategories.cfm: line 49

                47 : <input type="checkbox" name="checkbox"
                48 : value="#get_All_Cats.Cat_ID#"
                49 : <cfif listfind(ValueList(get_All_Cats.Cat_ID)get_Selected_Cats.CatID99) gt 0>
                50 : checked="checked"
                51 :


                • 5. Re: checked boxes
                  jdeline Level 1
                  Try placing a comma after (get_All_Cats.Cat_ID). BTW, if this is in a loop, you will be doing a ValueList( ) each pass through the loop. Better to place it outside the loop:
                  <CFSET foo = ValueList(Get_All_Cats.Cat_id)>
                  and refer to foo inside your loop.
                  • 6. Re: checked boxes
                    c_wigginton Level 1
                    Here's a method where you let the database do the work in setting which input box is checked.

                    <cfquery name="catUnion" datasource="#application.ds#">
                    SELECT DISTINCT (CT.Cat_Name) AS Cat_Name, Cat_ID,'' as checked
                    FROM category_table CT
                    where CT.cat_id not in (
                    select catID99 from cattoprodcut where ProductID99 = '#session.ProductID#'
                    )
                    union all
                    SELECT DISTINCT (CT.Cat_Name) AS Cat_Name, Cat_ID,'CHECKED' as checked
                    FROM category_table CT
                    where CT.cat_id in (
                    select catID99 from cattoprodcut where ProductID99 = '#session.ProductID#'
                    )
                    order by 1 ASC
                    </cfquery>


                    <cfoutput query="catUnion">
                    #catUnion.Cat_Name# <input type="checkbox" name="selCats" value="#catUnion.Cat_Id#" #catUnion.checked#><br/>
                    </cfoutput>
                    • 7. Re: checked boxes
                      KeithLaw999 Level 1
                      ok i have tried that but now nothing the check boxes show but none of them are checked, as there should be.

                      this is inside a cfoutput query not a loop.

                      any ideas?
                      • 8. checked boxes
                        cf_dev2 Level 1
                        Dump the query and check the values of the checked column. Are any of them "Checked" or are they all an empty string ""
                        • 9. Re: checked boxes
                          KeithLaw999 Level 1
                          ok yes they are all set as empty string, but i know for a fact there should be atleast 2 boxes ticked that have a category link to the item i am viewing?

                          wierd?
                          • 10. Re: checked boxes
                            cf_dev2 Level 1
                            This half of the query should return the categories that are "checked". Run this query separately and dump it. Does it contain any results? If not, check the columns to see if the statement is correct. Also look at the sql statement debugging output to see what values were passed for #session.ProductID#

                            SELECT DISTINCT (CT.Cat_Name) AS Cat_Name, Cat_ID,'CHECKED' as checked
                            FROM category_table CT
                            where CT.cat_id in (
                            select catID99 from cattoprodcut where ProductID99 = '#session.ProductID#'
                            )
                            • 11. Re: checked boxes
                              cf_dev2 Level 1
                              In case you're interested here's another sql option using a LEFT JOIN. Not tested but the syntax should work for MS SQL Server / MySql
                              • 12. Re: checked boxes
                                KeithLaw999 Level 1
                                Hi many thanks for your help i just have one more page of check boxes which needs the same checks but with a differnt query which is below.

                                i have the query below which shows my check boxes fine i need to add checks if RM.Product_ID64 = session.#session.part#

                                hope you can understand this, its a bit more complex

                                thanks once again
                                • 13. checked boxes
                                  cf_dev2 Level 1
                                  You could try a variation of the query above. Again, not tested ..

                                  Edit - on second thought perhaps all you need is INNER JOINs