Skip to main content
Inspiring
July 29, 2009
Question

How to uncheck checkbox after form has been submitted

  • July 29, 2009
  • 3 replies
  • 6901 views

Hi,

I have a complex form which gets submitted to itself using post.  I have added a checkbox to this form.

           

If a user submitted a form without filling in all the required fields then the form displays a message but retains the values that user entered earlier for convenience. When a user sumitts the form sucessfully, I would like to uncheck the checkbox. Any ideas as how to do it.

I tried <cfparam name="form.post_red" default=""> but it didn’t work.

Any ideas?

Thanks in advance.

Joe Green

This topic has been closed for replies.

3 replies

Inspiring
July 30, 2009

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.

Inspiring
July 30, 2009

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.

July 30, 2009

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.

July 29, 2009

<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.

Inspiring
July 29, 2009

Don't do whatever you are doing to check it in the first place.