-
1. Re: How to uncheck checkbox after form has been submitted
Dan Bracuk Jul 29, 2009 9:20 AM (in response to GreenGoneMad)Don't do whatever you are doing to check it in the first place.
-
2. Re: How to uncheck checkbox after form has been submitted
CFMXPrGrmR Jul 29, 2009 10:47 AM (in response to GreenGoneMad)<cfif form.post_red EQ "on">
<cfset form.post_red = "off">
</cfif>
You may have to replace the "on" with a 1 and the "off" with a 0. Try it both ways and if it doesn't work post back.
-
3. Re: How to uncheck checkbox after form has been submitted
TLC-IT Jul 30, 2009 7:49 AM (in response to GreenGoneMad)In a classic, HTML, "self-posting form," you know that (except on the initial entry into the page) you're going to be getting some POST data representing whatever's been entered on that form. So, when and if you see that, the first thing that you must do is to process and evaluate those inputs. I usually process these into a struct which I keep in the Session pool, merging whatever POST-variables I find with what may already be there.
The second thing that an HTML page-handler always does, whether there were any POST variables present or not, is to build the HTML necessary to render the new, updated page-image on the user's screen. You therefore determine, each and every time, whether that <cfinput type="checkbox"> tag, which you have for whatever reason just decided to generate, should, or should not, include the keyword, checked.
The HTML you prepare will then be sent back to the user's browser and displayed there: it is an entirely-new HTML stream that just happens to be quite similar to the last one that the browser received. If the browser did its work well, there is no "screen flicker" and it simply appears to the user that almost nothing changed (the checkbox is now un-checked). But in fact, every HTML stream stands alone.
-
4. Re: How to uncheck checkbox after form has been submitted
GreenGoneMad Jul 30, 2009 8:21 AM (in response to TLC-IT)I tried "off" and 0, both didn't work. I guess I could use hidden field to control checkbox. It's strange that in coldfusion we cannot control the status of a checkbox.
-
5. Re: How to uncheck checkbox after form has been submitted
CFMXPrGrmR Jul 30, 2009 8:25 AM (in response to GreenGoneMad)Do a <cfdump var=#form#> on your action page and see what value you are getting for your checkboxes. Do this with and without them checked and write back what you see. I do these quite a bit so there's a way to get it figured out.
-
6. Re: How to uncheck checkbox after form has been submitted
Dan Bracuk Jul 30, 2009 9:13 AM (in response to GreenGoneMad)You can use cf to control the status of a check box.
<input type ="checkbox" name="whatever"
<cfif something>checked="checked"</cfif>
>
-
7. Re: How to uncheck checkbox after form has been submitted
GreenGoneMad Jul 30, 2009 10:33 AM (in response to CFMXPrGrmR)I did <cfdump var=#form#> and it shows the value of the checkbox and checkbox is checked.
-
8. Re: How to uncheck checkbox after form has been submitted
GreenGoneMad Jul 30, 2009 10:40 AM (in response to Dan Bracuk)I did following but it doesn't work because user checked the box before submitting, after the form has been submitted to itself, the checkbox remains checked.
<input name="post_red" type="checkbox" value="yes" <cfif isdefined("form.post_red")><cfoutput>checked</cfoutput></cfif>>Red
-
9. Re: How to uncheck checkbox after form has been submitted
CFMXPrGrmR Jul 30, 2009 11:15 AM (in response to GreenGoneMad)If you could post more code that could help.
Anyhow I've thrown together some code that may help you understand it a little clearer. Create a new page and paste this in. It should show you how CF handles the checkbox values.
<cfoutput>
<cfparam name="form.chk_1" default="" />
form.chk_1 default value or after being set in the form:<br />
<cfdump var="#form.chk_1#"><form action="#cgi.SCRIPT_NAME#" method="post" name="test">
<input name="chk_1" type="checkbox" <cfif form.chk_1 EQ "on">checked</cfif><br /><br />
<input name="submit" type="submit" value="Submit" />
</form>
Form.chk_1 value after manually setting it:<br />
<!--- If it's on I want to turn it off --->
<cfif form.chk_1 eq "on">
<cfset form.chk_1 = "off">
</cfif><cfdump var="#form.chk_1#">
</cfoutput>
-
10. Re: How to uncheck checkbox after form has been submitted
Dan Bracuk Jul 30, 2009 11:39 AM (in response to GreenGoneMad)You are on the right track with that bit of code. The problem is that you are using a simple isDefined function to solve a logic problem that is not that simple.
I interpret your opening post to say, if the user screws up, keep the form fields. If he submits the form correctly, don't check the box. Does this accurately describe what you are trying to accomplish?