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 re-display a list of checkbox choices when returning to a page

Status
Not open for further replies.

Guildnavigator

Programmer
Jul 5, 2001
3
GB
HI,

I have a list of checkboxes on each page, the user can click any number of checkboxes and move onto the other pages via a list of links which were generated from the database.

If the user clicks on some check boxes and goes to another page via a link, then returns to the page where he has checked the boxes, how do I display the boxes checked,which he checked previously,

*note he moves around the pages via a list of links.
Any help with examples would be much appreciated.

Cheers
Guild
 
Hey Guild,

I would store these as session variables. The only difficulty is that on the page containing these check boxes, you have to make sure that every link off that page points to a script which will store these values. Iow, if you have the check boxes and several links to different parts of the site, each of these links must point to an "action" script which stores the values of the check boxes and then re-directs the visitor to the correct page. Other than that, it's a pretty simple thing to do. Here's an example.

<cfparam name=&quot;session.check1&quot; value=&quot;0&quot;>
<cfparam name=&quot;session.check2&quot; value=&quot;0&quot;>

.........

<form action=&quot;action.cfm&quot;.....>
<input type=&quot;checkbox&quot; name=&quot;check1&quot; <cfif session.check1 is &quot;1&quot;>checked</cfif>>
<input type=&quot;checkbox&quot; name=&quot;check2&quot; <cfif session.check2 is &quot;1&quot;>checked</cfif>>

On the action.cfm script, have this:

<cfif isdefined(&quot;form.check1&quot;)>
<cfset session.check1 = 1>
<cfelse>
<cfset session.check1 = 0>
</cfif>
<cfif isdefined(&quot;form.check2&quot;)>
<cfset session.check2 = 1>
<cfelse>
<cfset session.check2 = 0>
</cfif>

Let me know if you have any problems with it as I didn't test the code.
GJ
 
First, make sure that each checkbox has a default value of &quot;off&quot; by using a hidden form field for each one:

<form type=&quot;hidden&quot; name=&quot;checkbox1&quot; value=&quot;off&quot;>

This is necessary since checkboxes pass no value whatsoever if they aren't checked. Having done this, you can check for the checked checkboxes on your result page with:

<cfif #form.checkbox1# contains &quot;on&quot;>

since checked checkboxes will have the value &quot;off,on&quot;.

Now, in order to preserve a record of checked checkboxes, you could use:

<cfif #form.checkbox1# contains &quot;on&quot;>
<cfset #session.check1# = &quot;yes&quot;>
</cfif>

If you use this method, I would also suggest putting the following line in your application.cfm file:

<cfparam name=&quot;session.check1&quot; default=&quot;no&quot;>

This will eliminate the necessity of checking for the session.check1 variable with
<cfif #parameterexists(session.check1)#>

instead, your checkboxes can now read:

<input type=&quot;checkbox&quot; name=&quot;checkbox1&quot; value=&quot;on&quot; <cfif #session.check1# is &quot;yes&quot;>checked</cfif>>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top