Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass the checked values to the next screen ...

Status
Not open for further replies.

request

Programmer
Dec 5, 2001
76
US
I have a CF screen where I have to enter the search criteria. Once the search criteria is entered, the SUBMIT button is clicked to display the records that meet the search criteria on the LIST screen.

At the end of each record displayed on the LIST screen, there is a checkbox. The user can select checkboxes of multiple records and hit the SUBMIT button on the LIST screen. What this does is that for whichever records the checkboxes were checked, a corresponding record is inserted in our HISTORY table. Also, for each record that is displayed on the list screen, there is an id field associated with it.

My question is how can I pass the list of id values of the records for which the checkboxes have been checked and pass it on to the next screen?

Please let me know. Any help will be appreciated. Thanks.
 
You can name all the check boxes with the same name and the value of the id. When multiple boxes are checked and the submit button is clicked, a "," delimited list is sent in the check box name eg. myCheckBox = "id1,id2,id4,id44".

When you get to the next page, you can use a list loop to loop through the form.myCheckBox and insert each of the id's into the database. Let me know if you require more detailed code.



The only dumb questions are the ones that are never asked
 
twcman:

It will be really nice if you can give me the detailed code.

Thanks a ton.
 
Here ya go.....

In the action page you will have:

<cfloop index=&quot;i&quot; list=&quot;#form.myCheckBox#&quot; delimiters=&quot;,&quot;>
<cfquery name=&quot;myQuery&quot; datasource=&quot;myDatasource&quot;>
INSERT INTO yourTable(id,other_variables) VALUES(#i#,#other_variables#)
</cfquery>
</cfloop>

Hope this helps

Chris Scott
The Whole Computer Medical Systems
 
For
form.cfm -
Code:
<form action=&quot;nextpage.cfm&quot; method=&quot;post&quot;>
   <!--- name all the checkboxes with the same name --->
   <input type=&quot;checkbox&quot; name=&quot;lstCheckboxes&quot; value=&quot;id1&quot;> ID 1<br />
   <input type=&quot;checkbox&quot; name=&quot;lstCheckboxes&quot; value=&quot;id2&quot;> ID 2<br />
   <input type=&quot;checkbox&quot; name=&quot;lstCheckboxes&quot; value=&quot;id3&quot;> ID 3<br />
   <input type=&quot;submit&quot;>
</form>

then, on
nextpage.cfm -
Code:
<!--- make sure there is always a value
      if no checkboxes are checked, FORM.lstCheckboxes
      won't exist, so CFPARAM it to get around that --->
<CFPARAM name=&quot;FORM.lstCheckboxes&quot; default=&quot;&quot;>

You selected:<br />
<ul>
<!--- since FORM.lstCheckboxes will contain a comma-delimited
      list of all the values checked, you can simply
      loop through that list in a CFLOOP with the list
      attribute --->
<CFLOOP list=&quot;#FORM.lstCheckboxes#&quot; index=&quot;whichCheckbox&quot;>
   <li><CFOUTPUT>#whichCheckbox#</CFOUTPUT></li>
</CFLOOP>
</ul>

That's pretty much all there is to it.
Do whatever you need within the loop.



-Carl
 
I am sorry I did not specify one of the things clearly.

I have only one checkbox on the form page.
<td><input type=&quot;Checkbox&quot; name=&quot;Request&quot; value=&quot;Yes&quot; align=&quot;right&quot;></td>

However, on the action page, when the search results are displayed, there is a checkbox next to each record.

It is like an order page where whatever they want to order, they can check the checkbox for those records.

In this scenario, how will I identify for which record the checkbox was checked?
 
Just like the above.

The action page will need to be another form that submits to another action page (or itself). And the checkboxes will need to have individual values, just like the examples above.



-Carl
 
twcman:

I tried implementing as per your suggestion and it worked. Thanks a lot.
Also, I appreciate everybody's response.

However, I have another problem.

From the form page, there is a field called as copiesavailable. On the action page, this value is retrieved as comma separated values (just like checkbox values).

I have to implement a logic in the action page, where I have to check for each record displayed on the form page, if the checkbox was checked and also what was the copiesavailable field value. How can I do it?

As always, thanx for the help.
 
Let me restate my problem that I had originally put :

I have a display page where I am displaying records with a checkbox at the end of each record. It looks like as follows:

Title Copies CopiesAvailable &quot;Checkbox&quot;

On this page, the user can check one or multiple checkboxes.

On the form page, I have code like below:

<tr bgcolor=&quot;#rowColor#&quot; bordercolor=&quot;gray&quot; align=&quot;center&quot;>
<td>&nbsp;#ti#&nbsp;
</td>
<td>&nbsp;#copies#&nbsp;
</td>
<td>&nbsp;#copiesavailable#&nbsp;
</td>
<td><input type=&quot;Checkbox&quot; name=&quot;Request&quot; value=&quot;#orderid#&quot; align=&quot;right&quot;></td>

Now on the action page, I need to determine which checkboxes have been checked and also the corresponding copies available field value. How can I do it?

Please help. I had implemented what had been suggested above. But I have a problem where I am not able to figure out the corresponding copies available field value for the checkboxes that have been checked.

Thanks.
 
One way would be to create hidden fields on the form with the ID number as part of the name... then loop through the id's passed in the checkbox field and grab the values of the hidden fields.

Something like:

formpage.cfm-
Code:
    :
<tr bgcolor=&quot;#rowColor#&quot; bordercolor=&quot;gray&quot; align=&quot;center&quot;>
    <td> #ti# 
    </td>
    <td> #copies# 
    </td>
    <td> #copiesavailable# 
         <input type=&quot;hidden&quot; name=&quot;copiesavailable_#orderid#&quot; value=&quot;#copiesavailable#&quot;>
    </td>
    <td><input type=&quot;Checkbox&quot; name=&quot;requestids&quot; value=&quot;#orderid#&quot; align=&quot;right&quot;></td>
    :

then, in the action/ok page:
Code:
<CFLOOP list=&quot;#FORM.requestids#&quot; index=&quot;whichOrderID&quot;>
   <CFOUTPUT>Order ID #whichOrderID# was checked, with a copiesavailable quantity of #FORM[&quot;copiesavailable_&quot; & whichOrderID]#<br /></CFOUTPUT>
</CFLOOP>

Note: I changed the name of the checkboxes to &quot;requestids&quot;. &quot;Request&quot; is a &quot;reserved keyword&quot; in ColdFusion, in that it's the name of a scope. ColdFusion never complains about code that (mis)uses reserved keywords... but it's always good practice to avoid using them.


-Carl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top