Reply to topic
Holding a checkbox value on a recursive submit
jamie
HostMySite Sales Rep
HostMySite Sales Rep

Joined: 19 Mar 2004
Posts: 770
Location: Newark, De
Reply with quote
Ok, my next question about checkboxes. I have a form that searching a database based off values in several checkboxes. I.e.

Code:
Search the database for what color car (may include more than one):

[ ] Red
[x] Black
[x] White


So with the above type of search, I have the form returning the information found to itself, which displays the relevant information with a CFOutput statement. However, when it does this the checkboxes no longer hold a check. How can I preserve the checkbox state and re-create it on the page when it reloads?
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1031
Location: Felton, Delaware
Reply with quote
isn't this a viewstate thing? Jamie, you should be using ASP.NET Wink Im not the CFGuru anymore so I'll just stop here, but I'm positive that you should be utilizing viewstate somehow.
jamie
HostMySite Sales Rep
HostMySite Sales Rep

Joined: 19 Mar 2004
Posts: 770
Location: Newark, De
Reply with quote
Nope, not going to ASP.NET. I'm using CF + MySQL, and Javascript to supplement if I have to.
byron
Forum Admin

Joined: 07 Mar 2004
Posts: 160
Location: Newark, DE, USA
Reply with quote
<input type="checkbox" name="red" value=1<cfif isDefined("form.red") and form.red eq 1> CHECKED</cfif>>

I believe with view state and asp.NET this is a built in part of the checkbox control, so you wouldn't be adding this line.

Someday I'll go back to the dark side and figure out .NET
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1031
Location: Felton, Delaware
Reply with quote
I wasn't actually suggesting that you move to .NET... sorry. In .NET viewstate is tracked automatically for the sake of postbacks and what not. They figured out that everybody was doing at least a little, and in some cases some extensive, tracking of viewstate so they worked in an automated process just for this.

Byron got this for ya Wink
jamie
HostMySite Sales Rep
HostMySite Sales Rep

Joined: 19 Mar 2004
Posts: 770
Location: Newark, De
Reply with quote
Thanks for the push in the right direction. The cfif statement actually ended up being this:

Code:
<cfif isDefined("form.color") and trim(form.color) eq "white"> CHECKED</cfif>
jamie
HostMySite Sales Rep
HostMySite Sales Rep

Joined: 19 Mar 2004
Posts: 770
Location: Newark, De
Reply with quote
Two things:

1. The last three posts were deleted by me. I got rid of the first two because they didn't contribute to the thread and they were needlessly arguing. Please refrain from doing that again (you both know who you are). The third post in the series was referencing the others, so it became kinda senseless once I removed them (sorry Byron).

2. Now, back to the point. My code now looks something like this:

Code:
<form name="form1" method="post" action="mycards.cfm">
<fieldset><legend>Search Parameters</legend>
<input type="checkbox" name="color" value="white"<cfif isDefined("form.color") and trim(form.color) eq "white"> CHECKED</cfif>>White
<input type="checkbox" name="color" value="blue"<cfif isDefined("form.color") and trim(form.color) eq "blue"> CHECKED</cfif>>Blue
.
.
.
</form>


However it's not consistently saving the checkbox information. If you click on "white" then it is saved, however if you click on 'white' and 'blue' they are both cleared.

A copy of this script can be found at

http://mtgotradingpost.com/mycards.cfm

Suggestions are welcome!
steve
HostMySite Developer

Joined: 02 Mar 2004
Posts: 30
Reply with quote
Jamie,

Your checkbox fields are named the same so if they are both checked form.color will be '1,1'

If you give the form fields separate names you will be able to distinguish one from the other.

-Steve
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1031
Location: Felton, Delaware
Reply with quote
ah ha you are correct. Good eye. I looked that over and didn't catch it.
checkboxes
kbrocx


Joined: 13 Oct 2004
Posts: 43
Location: Seattle
Reply with quote
If you actually WANT to pass your checkboxes in a list like that then you could do <cfif isDefined('form.color') And ListFind('#form.color#','white')>Checked</cfif>
Holding a checkbox value on a recursive submit
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic