0

/t5/coldfusion-discussions/help-with-simple-checkbox-form/td-p/302325
Jul 10, 2007
Jul 10, 2007
Copy link to clipboard
Copied
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
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
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
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:
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:
LEGEND
,
/t5/coldfusion-discussions/help-with-simple-checkbox-form/m-p/302326#M27163
Jul 10, 2007
Jul 10, 2007
Copy link to clipboard
Copied
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
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
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

Guest
AUTHOR
/t5/coldfusion-discussions/help-with-simple-checkbox-form/m-p/302327#M27164
Jul 10, 2007
Jul 10, 2007
Copy link to clipboard
Copied
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
Thanks for your help
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Contributor
,
/t5/coldfusion-discussions/help-with-simple-checkbox-form/m-p/302328#M27165
Jul 10, 2007
Jul 10, 2007
Copy link to clipboard
Copied
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:
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:
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/help-with-simple-checkbox-form/m-p/302329#M27166
Jul 10, 2007
Jul 10, 2007
Copy link to clipboard
Copied
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.
Should you ever want to do that, cfcookie is the way to go.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Engaged
,
LATEST
/t5/coldfusion-discussions/help-with-simple-checkbox-form/m-p/302330#M27167
Jul 11, 2007
Jul 11, 2007
Copy link to clipboard
Copied
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>
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>
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

