• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

checked boxes

New Here ,
Aug 08, 2007 Aug 08, 2007

Copy link to clipboard

Copied

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?
TOPICS
Advanced techniques

Views

888

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 08, 2007 Aug 08, 2007

Copy link to clipboard

Copied

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>
>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 08, 2007 Aug 08, 2007

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 14, 2007 Aug 14, 2007

Copy link to clipboard

Copied

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"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 14, 2007 Aug 14, 2007

Copy link to clipboard

Copied

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 :


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 14, 2007 Aug 14, 2007

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 14, 2007 Aug 14, 2007

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 14, 2007 Aug 14, 2007

Copy link to clipboard

Copied

Dump the query and check the values of the checked column. Are any of them "Checked" or are they all an empty string ""

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 14, 2007 Aug 14, 2007

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 14, 2007 Aug 14, 2007

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 14, 2007 Aug 14, 2007

Copy link to clipboard

Copied

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#'
)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 14, 2007 Aug 14, 2007

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 15, 2007 Aug 15, 2007

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 15, 2007 Aug 15, 2007

Copy link to clipboard

Copied

LATEST
You could try a variation of the query above. Again, not tested ..

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation