Copy link to clipboard
Copied
Hello, I have a search results page that has a checkbox next to each returned record. Is there a way to append its value to a string via an Onclick function? My search results page uses paging as well, that is why I was wondering if it can be done as they click the checkbox.
Copy link to clipboard
Copied
Which variables hold the value of the search results? If one knows this, then answering the question will be easy.
Copy link to clipboard
Copied
The name of my form is "get_records" and the name of my checkbox is "f_selected_record".
I was using this code but I was only getting the current id of the checkboxes on the current page I was on.....so if I did a search and clicked on a checkbox on page 1 and went to page 2 clicked 2 checboxes, I would only have the 2 ids from page 2.
<cfif isdefined("form.get_records")>
<cfloop index="i" list="#Form.f_selected_record#" delimiters=";">
<cfoutput><cfset session.get_all_records = ListAppend(session.get_all_records,'#i#')></cfoutput>
</cfloop>
</cfif>
Copy link to clipboard
Copied
pmlink360 wrote:
The name of my form is "get_records" and the name of my checkbox is "f_selected_record".
I was using this code but I was only getting the current id of the checkboxes on the current page I was on.....so if I did a search and clicked on a checkbox on page 1 and went to page 2 clicked 2 checboxes, I would only have the 2 ids from page 2.
<cfif isdefined("form.get_records")>
<cfloop index="i" list="#Form.f_selected_record#" delimiters=";">
<cfoutput><cfset session.get_all_records = ListAppend(session.get_all_records,'#i#')></cfoutput>
</cfloop>
</cfif>
If the name of your form is "get_records", then this statement is absurd: <cfif isdefined("form.get_records")>. The statement suggests that "get_records" is the name of a field in the form. Is it?
You said you have a search results page that has a checkbox next to each returned record. My question is, which variables hold the values of the returned records? Do you have 2 forms, one posting to the results page and one on the results page(in which are the checkboxes)?
Copy link to clipboard
Copied
I typo'ed that....I meant f_selected_record which is the name of the checkbox.This way is not working so I'm trying to understand if anyone has an example of adding the value of a checkbox to a string via an onClick method. I do not have 2 forms, the information is just output to the results page.
Copy link to clipboard
Copied
Put the following files in the same directory, and do the test. I hope it tells you things you wish to know.
form_page.cfm
<cfform action="results_page.cfm">
<!---Using same name for the fields means the form will submit a comma-delimited list (under one field name) --->
Checkbox 1: <cfinput name="f_selected_record" type="checkbox" value="value_of_checkbox_1"><br>
Checkbox 2: <cfinput name="f_selected_record" type="checkbox" value="value_of_checkbox_2"><br>
Checkbox 3: <cfinput name="f_selected_record" type="checkbox" value="value_of_checkbox_3"><br>
<cfinput name="sbmt" type="submit" value="Post to results page">
</cfform>
results_page.cfm
<!--- Variable session.get_all_records is initialized whenever a form is submitted --->
<cfset session.get_all_records = "">
<!--- Variable session.get_all_records collects and stores the submitted records cumulatively, including repeated submissions --->
<!---<cfparam name="session.get_all_records" type="string" default="">--->
<cfif isdefined("form.f_selected_record")>
<!--- Remember it is by default a comma-delimited list--->
<cfloop index="i" list="#Form.f_selected_record#">
<cfset session.get_all_records = ListAppend(session.get_all_records,'#i#')>
</cfloop>
</cfif>
session.get_all_records: <cfoutput>#session.get_all_records#</cfoutput>