Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to manage a group of checkboxes?

Status
Not open for further replies.

fiuPikeOY

Programmer
Jun 14, 2004
143
US
Hello,

I'm creating a test in coldfusion where some of the answers are check-boxes, and the right answer for those is all the answers that apply (eg. A, B, and C).

What's the best way to manage a checkBox group? For examaple q5 has 4 choices. Can I give those checkBoxes the same name since they are for q5, or will they be overwritten. What's the best way to check for the right answer (eg. for q5 is B and C and D)

Thanks for all your help
 
Assuming your value for these checkboxes are for example 1, 2, 3, and 4 on question 1. The user clicks 2 & 3 you can check the value:

<cfoutput>#form.q1#</cfoutput> will return 2,3 in a comma delimeted list.

You can then use listcontains(#form.q1#, "2") to see if it contained the correct answer of 2.

DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
DeZiner is right, but you want to use ListFind(FORM.q1,"2") instead of ListContains(). ListContains() would return TRUE if you had a list of "1,3,12", since it looks for items that CONTAIN a "2" character.

-Tek
 
Be warned though, if no checkbox by a name is checked, the value and the field element itself is not passed.. so you need to..

You'll need to use parameterexists, isDefined, or CFPARAM for protection against that..

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top