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

Populating dynamic checkboxes

New Here ,
Apr 15, 2007 Apr 15, 2007

Copy link to clipboard

Copied

I'm hung up on figuring out how to populate the checkbox on an update. What I have is a list of extras that are applied to a workorder with a foreign key tied to the ID of the extra. What I am trying to figure out is how to check the box if it's in the foreign key DB column of the workorder for updating. The first query works great on the initial INSERT and the second query would only display the original extras. Is there some way to combine them or use a ListContains statement?

<cfquery name="ExtrasUpdate" datasource="#DataSource#" username="#dbUserName#" password="#dbPass#">
SELECT ID, Name, Price FROM HVAC_extras WHERE ID IN (#SESSION.HVAC.ExtrasID#)
</cfquery>

<cfquery name="Extras" datasource="#DataSource#" username="#dbUserName#" password="#dbPass#">
SELECT * FROM HVAC_extras
ORDER BY ID
</cfquery>

<cfoutput query="Extras">
<table width="98%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="9%">
<cfinput type="checkbox" name="Extras" value="#Extras.ID#" checked="no">
</td>
<td width="91%"><a href="/WorkOrders/data/extras.cfm?ID=#Extras.ID#" target="_blank">#Extras.Name#</a>
- #DollarFormat(Extras.Price )#</td>
</tr>
</table>
</cfoutput>

Thanks for any help.
Hope this makes sense!
TOPICS
Advanced techniques

Views

547

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

correct answers 1 Correct answer

LEGEND , Apr 16, 2007 Apr 16, 2007
you CAN use <cfinput type="checkbox"> and still achieve what you want:

Aside1: if you already have the id's of extras for the workorder
in question stored in SESSION.HVAC.ExtrasID (presumably as a
comma-delimited list), then you do not need your ExtrasUpdate query at all.

Aside2: instead of outputting a whole table for each Extra, why
don't you move the <cfoutput query="Extras"> INSIDE the <table></table>,
so you output separate rows for each extra inside same one table?

try this:

<cfq...

Votes

Translate

Translate
LEGEND ,
Apr 15, 2007 Apr 15, 2007

Copy link to clipboard

Copied

Don't use cfinput for a checkbox. Use input instead. Using cfinput adds nothing useful and prevents you from doing this sort of thing.

<input <cfif some_condition_is_met>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
Community Expert ,
Apr 15, 2007 Apr 15, 2007

Copy link to clipboard

Copied

I don't understand what the link is doing in the form. Couldn't you just put the data as values in form fields or hidden fields, and then submit to extras.cfm?

> The first query works great on the initial INSERT and the second query
> would only display the original extras.

Aparently only data that corresponds to IDs in SESSION.HVAC.ExtrasID has been updated. It suggests there are 2 sets of IDs, those whose data is updated and those whose data is not. I would look into that. How do the insert/update queries look like?

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 ,
Apr 15, 2007 Apr 15, 2007

Copy link to clipboard

Copied

Thanks for the help! Eliminating the cfinput got rid of some errors for me! BKBK, the form I submit is a different address, the links allow the customer to view the description of the extras before submitting the form. The following code works great with one "extras" value for example an ID of 4 returns the correctly checked box but when I have multiple values like 1,2,3 I don't know how to break them out seperately similar to an SQL IN query ie. SELECT ID FROM SomeTable WHERE ID IN (#Extras.ID#).

<cfoutput query="Extras">
<table width="98%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="9%">
<input type="checkbox" name="Extras" value="#Extras.ID#" <cfif Extras.ID EQ SESSION.HVAC.ExtrasID>checked</cfif>>
</td>
<td width="91%"><a href="/WorkOrders/data/extras.cfm?ID=#Extras.ID#" target="_blank">#Extras.Name#</a>
- #DollarFormat(Extras.Price )#</td>
</tr>
</table>
</cfoutput>
Thanks again for your help!

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
Community Expert ,
Apr 15, 2007 Apr 15, 2007

Copy link to clipboard

Copied

> the form I submit is a different address, the links allow the customer to
> view the description of the extras before submitting the form.

OK.

> for example an ID of 4 returns the correctly checked box but when I have
> multiple values like 1,2,3 I don't know how to break them out seperately
> similar to an SQL IN query

I think you already have that functionality. Suppose there are two or more checkboxes with the same name, extras. If they are checked and submitted, form.extras will be a comma delimited list of their respective values. Run the test. Is that what you meant?

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 ,
Apr 16, 2007 Apr 16, 2007

Copy link to clipboard

Copied

you CAN use <cfinput type="checkbox"> and still achieve what you want:

Aside1: if you already have the id's of extras for the workorder
in question stored in SESSION.HVAC.ExtrasID (presumably as a
comma-delimited list), then you do not need your ExtrasUpdate query at all.

Aside2: instead of outputting a whole table for each Extra, why
don't you move the <cfoutput query="Extras"> INSIDE the <table></table>,
so you output separate rows for each extra inside same one table?

try this:

<cfquery name="Extras" datasource="#DataSource#" username="#dbUserName#"
password="#dbPass#">
SELECT * FROM HVAC_extras ORDER BY ID;
</cfquery>

<table width="98%" border="0" cellspacing="2" cellpadding="2">
<cfoutput query="Extras">
<tr>
<td width="9%">
<cfif listfind(session.hvac.extrasid, Extras.ID)>
<cfinput type="checkbox" name="Extras" value="#Extras.ID#" checked="yes">
<cfelse>
<cfinput type="checkbox" name="Extras" value="#Extras.ID#" checked="no">
<cfif>
</td>
<td width="91%"><a href="/WorkOrders/data/extras.cfm?ID=#Extras.ID#"
target="_blank">#Extras.Name#</a> - #DollarFormat(Extras.Price )#
</td>
</tr>
</cfoutput>
</table>

--

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com

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 ,
Apr 16, 2007 Apr 16, 2007

Copy link to clipboard

Copied

Thank you Azadi! It works like a charm. Looks simple when I see it now.

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 ,
Apr 16, 2007 Apr 16, 2007

Copy link to clipboard

Copied

LATEST
happy to help!
--

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com

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