?
Solved

Checkbox checked

Posted on 2004-04-24
7
Medium Priority
?
414 Views
Last Modified: 2013-12-24
I have several checkboxes--not related/grouped to each other.
I want the form to show the checkboxes as checked or unucheked depending if there is a matching value in the databse.  I took a wild stab at it  and came up with this but it didn't work:

          <input type="checkbox" name="test" value="1" <cfif #getSearch.test#
                 IS '2'>checked</cfif>>

I get an error that basically says the form.test does not exist.
0
Comment
Question by:champ_010
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 18

Expert Comment

by:Plucka
ID: 10906556
Hi champ_010,

That should work, see this simple example.

<cfset value = 1>
<input type="checkbox" name="test" value="1" <cfif value eq 1 >checked</cfif>>

Your error refers to form.test which is not on the line of code above, are you sure the error relates to this statement.

Regards
Plucka
0
 
LVL 11

Expert Comment

by:hart
ID: 10906749
kindly paste ur whole code [form code]

Regards
Hart
0
 
LVL 1

Expert Comment

by:aescribens
ID: 10907690
Try this...

<input type="checkbox" name="test" value="1" <cfif isdefined("#getSearch.test#") and #getSearch.test# neq "">checked</cfif>>

Regards,
ACE
0
Simple, centralized multimedia control

Watch and learn to see how ATEN provided an easy and effective way for three jointly-owned pubs to control the 60 televisions located across their three venues utilizing the ATEN Control System, Modular Matrix Switch and HDBaseT extenders.

 
LVL 1

Author Comment

by:champ_010
ID: 10909795

Sorry--to clarify it's not that my code or some of the ones above don't identify what's checked (matching what's in the database)--they do, however when I submit the form to itself to perform an UPDATE, the error tells me the #form.test# form field does not exist.

Summary: This is an UPDATE page.  I have used :
 
<input type="checkbox" name="test" value="1" <cfif #getSearch.test#
                 IS '2'>checked</cfif>>

to prefill the form from a cfquery to the database. The appropriate checkboxes appear checked or not checked as dictated by info from the database.  Now if I change some of the info in the pre-filled form and press update, everything is fine until it hits one of the checkboxes--then I get an error saying that the form field does not exist.  If my query is:

UPDATE tblSearches SET
  textboxinfo='#form.mytextbox#', checkboxinfo='#form.mycheckbox#', selectinfo='#form.mySelect#' WHERE testID=#url.id#

then it appears that the textbox formfield was fine, the select was fine but the error says the checkbox form field cannot be identified.

Any ideas?
0
 
LVL 1

Author Comment

by:champ_010
ID: 10909800

Sorry, it's a typo--my values do match as '2'

<input type="checkbox" name="test" value="2" <cfif #getSearch.test#
                 IS '2'>checked</cfif>>
0
 
LVL 18

Accepted Solution

by:
Plucka earned 400 total points
ID: 10909837
champ_010,

Ok, all checkboxes don't get posted in a form submit unless they are actually. So if you have a form field.

<input type="checkbox" name="test" value="1" <cfif #getSearch.test# IS '2'>checked</cfif>>

And you don't check the box, then on the action page it will not be defined, easiest way to overcome this is on the action page give all check boxes a default value of off

<cfparam name="form.test" default="0" />

So if it's checked it will now have a value of 1 and if it's not a value of 0.

Regards
Plucka
0
 
LVL 1

Author Comment

by:champ_010
ID: 10909895

An excellent thing to finally know!!!

Thanks Plucka.
0

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month10 days, 6 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question