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

Help with simple checkbox form

Guest
Jul 10, 2007 Jul 10, 2007
Hi all, I'm trying to create a little checkbox form that when clicked will save the "check" (boolean?) to a variable so when the page reloads it remains checked (and if then unchecked remains unchecked).

I'm totally new to Coldfusion so far have only come up the variable declaration?

<cfparameter name="IsBoxChecked" default = "no">

I know the html for checkboxes looks like whats below, but how can I add the CF tags to make it do what I want?

<input type="checkbox" name="IsBoxChecked" value="1"> MyValue
TOPICS
Getting started
540
Translate
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

correct answers 1 Correct answer

Contributor , Jul 10, 2007 Jul 10, 2007
Hi, maybe you could save the checkbox selections in a structure and store the structure as a session variable so it remains visible for the duration of the user's browser session.

To use session variables you must turn on session management in application.cfm (or cfc). Have a look at the code snippets below for examples on how you would do this:
Translate
LEGEND ,
Jul 10, 2007 Jul 10, 2007
Use cfcookie to keep track of the last selection.

Read the cookie each time you load the page. Then do something like this.

<input type="checkbox"
<cfif WasCheckedLastTime checked="checked"
name="IsBoxChecked" value="1"> MyValue
Translate
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
Guest
Jul 10, 2007 Jul 10, 2007
I don't think cfcookie is really what I'm looking for. I want it to save to a variable because I will use that variable in other statements in the same template. For example, if they check the box, I want to be able to add an additional column to a sql query. Also, I want them to be able to change many of them change the output of the query(ies).

Thanks for your help
Translate
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
Contributor ,
Jul 10, 2007 Jul 10, 2007
Hi, maybe you could save the checkbox selections in a structure and store the structure as a session variable so it remains visible for the duration of the user's browser session.

To use session variables you must turn on session management in application.cfm (or cfc). Have a look at the code snippets below for examples on how you would do this:
Translate
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
LEGEND ,
Jul 10, 2007 Jul 10, 2007
The cookie suggestion was based on what appears to be a wrong interpretation of the original question. I thought you meant that if the user came back to the page 3 days later, and had turned his computer off in between, you wanted your program to remember whether or not he had checked the box.

Should you ever want to do that, cfcookie is the way to go.
Translate
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
Engaged ,
Jul 11, 2007 Jul 11, 2007
LATEST
Use the preservedata attribute of the cfform tag.

Try the below:

<cfoutput>
Was the checkbox checked on the last refresh #IsDefined("form.refreshCheck")#<br>
</cfoutput>
<cfform method="post" preservedata="yes">
Stay checked on Refresh
<cfinput type="checkbox" name="refreshCheck">
<cfinput type="submit" name="refresh" value="refresh">
</cfform>
Translate
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