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

Onclick with checkboxes and add value to a string

Explorer ,
Feb 10, 2012 Feb 10, 2012

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.

TOPICS
Advanced techniques

Views

1.5K

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 ,
Feb 11, 2012 Feb 11, 2012

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.

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
Explorer ,
Feb 11, 2012 Feb 11, 2012

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>

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 ,
Feb 11, 2012 Feb 11, 2012

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

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
Explorer ,
Feb 11, 2012 Feb 11, 2012

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.

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 ,
Feb 12, 2012 Feb 12, 2012

Copy link to clipboard

Copied

LATEST

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>

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