Maintain Checkbox value when paging

Copy link to clipboard
Copied
Hello,
I cannot find a decent example of this anywhere. I am sure some of you have done this, however. Typical query
returning pages of results. In the results I have checkboxes. We can actually have hundreds of pages of
results, depending how crazy the user is with his/her search. I have to allow the user to select 4 total records
across those multiple pages and remember them upon a submit.
I'm trying to figure out the best way to handle this. I'm assuming you have to save the data and such in
session, but not sure the best way to handle it.
Any help would be much appreciated.
Thanks!
Copy link to clipboard
Copied
Your challange is that until a FORM is submitted, the data is on the client. Depending on how your paging system is working, it is very likely that no FORM data is submitted when the user pages through the data.
You can either do something using javascript to add the data in the URL to the pageing link, do something to submit a form when the pageing link is clicked, do something with AJAX to submit the data when the paging link is clicked, OR do something with javascript to store the data from request to request unitil the final form is submitted.
Once the data is submitted to the server, it is trival to store it in the session scope. But you need to look at the client side User Interface portion of your application and figure out HOW you are going to get data from the client machine to the server machine.

Copy link to clipboard
Copied
When I am paging data however, I have the STARTROW and ENDROW which I am displaying. I
assume CFLOOP CFQUERY holds the recordset on the client?
Could I in Javascript create an array of checkbox data to 1) hold the checkbox checked or not checked,
and 2) hold the value of the ID of the record?
Copy link to clipboard
Copied
edsarro1 wrote:
Could I in Javascript create an array of checkbox data t
You definitely COULD. What I don't know is what are ALL the methods you have to persist that data from request to request.
It would not be to hard, though, if you think outside of the 'box', or more accurately -- the frame. If you put your paging code inside an in-line frame on the page, it should not be to difficult to have JavaScript maintain the desired state data about checked form controls in the parent frame's scope.
Another technology that would do this type of stuff would be FLASH|FLEX. This is another technology designed to create and maintain User Interface state data over more then one screen.

Copy link to clipboard
Copied
I have had the same problem transferring the data from Page to Page. Here are the methods that I followed:
1) Query String: Pass the variables from page to page being appended in the query string as in:
http:///workexample/link.cfm?option1=Red&option2=Green
Appending the values to the URL as options are selected on each page. The URL shows all the messages selected previously and can be retrieved at the last page.
2) By the usage of the hidden form fields:
<input type="hidden" name="Name" id="Name" value="#FORM.Name#">
<input type="hidden" name="ID" id="ID" value="#FORM.ID#">
From Form to Form, pass the values of the variables as hidden and at the last page retrieve them using FORM.variable_name.
These are the easiest methods, that I used to transfer the values of the variable while paging.
Vijayvijay77.

Copy link to clipboard
Copied
The link isn't working. I think it was put in with a typo? Anyway, the way that I have things working is
I have this results page that has all of the data from the orginal query/search page. On this results page
I include a file that handles the navigation. When I click the next button, it calls the results page
and paginates the records. The way that I have it set up, I am not able to pass a URL variable.
Since I am not looking to resubmit the form either, we can't use session variables.
What I was thinking of using are cookies. The problem I have is exactly how to store them, what
to store in them, etc.
I was thinking of using an array of data, which would hold the node ids that are selected with the checkbox.
Maybe a double dimension array or maybe a struct since I need to have the checkbox checked or not
checked?
Basically, it's a user comes in, and through the 100 pages of records (50 rows per page, crazy huh?)
they select up to 4, and then submits. So I make the nodeID of the record the value of the checkbox
since I use that nodeID to find the record details. It's maintaining the checkbox state.
Thanks!
Copy link to clipboard
Copied
Cookies might be made to work.
JavaScript can certainly read and write data to and from cookies.
The main difficulty is that cookies do not do complex data types like arrays or structures. You could use one of the methods available to flatten complex data types into text that can be stored in cookies. Things like Json or the very old school wddx would do this. Or you can roll your on syntax of text data that represents the data structure you want.
Another possibility would be ajax. This would allow you to submit data to the server behind the scenes. Then you CAN use things like session scope data.

Copy link to clipboard
Copied
After looking at my application, cookies won't be the answer. What I will have to do it appears is just submit the form
when I do << prev 1 2 3 next >> operations. I have that working, but what I am doing is using the link to the form
to do it. I have the row values saved of course so paging is easy. The issue now is I think I need to create some
sort of function that sets the rows and then submits the form. This way I guess I can set the session variables
or check for them.
I wanted to set up the variables in either an array or struct, depending. Right now in my loop checkbox<i> is
created per row<i>, and so whatever the user selects will have to be saved. I only need 4 values saved, so
I am not sure what is best to save this to session.
Is this a course then you guys would follow?

Copy link to clipboard
Copied
OK, I've made some progress, and I could use some extra help here. I am able to save checkbox values to session
when I click on the next link to go to the next page. The row number links are another story, but I'll have to
debug that a bit. I am having some trouble trying to figure out when it's time to submit the whole thing:
<form name = "ResultsForm" action = <I think I need to call a function here?> method="post">
My checkboxes are all named "results". So, when I submit the page and move on:
<CFIF isDefined("FormResults")>
<CFSET Session.checkedvaluelist = ListAppend(Session.checkedvaluelist, Form.results)>
</CFIF>
So that's actually doing the job and getting my values in session. Depending on what the
type of the results are, I have to call a variety of forms. So, I believe I need to call a function
to handle that and spit out the right form.
Now, do I use a coldfusion function or go javascript? I also know I am going to have to
get other lists saved to know what page I am on and so forth.
Thanks!

Copy link to clipboard
Copied
OK, hopefully someone can help me out here with this last part....
I have put together some hidden form values and also some coldfusion lists in order to save values and pass them
to the client side for display. The issue I have now is the hardest part, which is handling when a user unchecks a box.
If the user does it on the same page, then we have no issue. Nothing is saved in session, so we don't have to delete
anything.
But, if a user selects a box, then pages to another page, selects a box, then returns to the previous page and unchecks
a box, we have a problem because as I thought I was deleting that value from the list, I wasn't. I have a couple of lists
set up:
1) I have a list saved in session of all values that were checked on a page. If the page is submitted through paging,
then the selections are remembered in session.
2) I have all pages in a session list which has a page where a box was checked off.
Issue is, when I uncheck a box, my algorithm checks to see if the current page is in that list, then checks the
checkbox values against my session list. If the value is found, remove the value from the session list. However,
sometimes I notice the wrong value is deleted.
I am not sure if I needed to create a list or 2 dimensional array of values with the page they were selected on?
This is a toughie, and I wonder if any of you have any ideas?
Thanks!

