0

How can I loop through results on a coldfusion page and grab the ids of the records that are checked and send just a list of ids to another page to be queried? The ids of the records are in the field next to the checkbox. Here is an example:

check  tag_num    serial_#  po_number  descrip
 []    FT0077769   test    12345       test   
 []    FT0077776   test    12345       test 
 []    FT0077789   test    12345       test   

If I check the first two records I want to send over the tag_num to another page to be queried and display only those two records.

I know I need to use a cfloop list and that I need to have a ',' list, but I also need to put each tag in ' ' because that list will go to a query on the processing page. I am just not sure where this goes in the first page. Inside the form?

Adrian J. Moreno
  • 14,350
  • 1
  • 37
  • 44
mac3201
  • 85
  • 1
  • 1
  • 10
  • 1
    If I understand you correctly, you want to see which items a user has checked? You could use jQuery to find checked rows. Or you can set this up as a form and set the id of the checkboxes to their corresponding tag_num. – WillardSolutions May 28 '14 at 20:47
  • 1
    RE: *need to put each tag in ' ' because that list will go to a query* No you don't. Just use [`cfqueryparam`](http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7f6f.html) and no quotes needed. More importantly, it protects queries from sql injection. Also, take at look the `list` attribute. I suspect you could use that with a `WHERE Col IN (...)` clause instead of looping. – Leigh May 28 '14 at 21:08
  • You did not provide enough information. Where does the "checking" of a record occur? – Dan Bracuk May 28 '14 at 21:45

1 Answers1

4

If you name all of your check boxes the same name, each with a different ID and value, you'll automatically get a list on the action page.

The form will look like this:

<cfloop query="myQuery">
   <input type="checkbox" name="tag" id="tag_#myQuery.tag_num#" value="#myQuery.tag_num#" />
</cfloop>

Now, when you check any of these check boxes and submit the form (using action="post"), the action page will be able to access the FORM scope. And the FORM scope will contain:

form.tag = FT0077769,FT0077776,FT0077789

If you've checked all three.

Does this help?

Adrian J. Moreno
  • 14,350
  • 1
  • 37
  • 44
  • 2
    First, I don't see a cfoutput tag anywhere. Next, you might want to mention what happens if no boxes are checked. – Dan Bracuk May 29 '14 at 01:16