champ_010
asked on
Checkbox checked
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.
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.
kindly paste ur whole code [form code]
Regards
Hart
Regards
Hart
Try this...
<input type="checkbox" name="test" value="1" <cfif isdefined("#getSearch.test #") and #getSearch.test# neq "">checked</cfif>>
Regards,
ACE
<input type="checkbox" name="test" value="1" <cfif isdefined("#getSearch.test
Regards,
ACE
ASKER
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.mytextb
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?
ASKER
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>>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
An excellent thing to finally know!!!
Thanks Plucka.
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