Connecting Tech Pros Worldwide Forums | Help | Site Map

tracking the number of checkboxes selected

rcollins207's Avatar
Newbie
 
Join Date: Sep 2008
Posts: 4
#1: Sep 3 '08
what i have to do is make sure that they only select a certain amount of items i have looked everywhere but it must be a simple thing that i cannot think of please any help would be great!! so i think that all i need to do is track the number that is selected when they click submit but i cannot find the answer please help me.


Expand|Select|Wrap|Line Numbers
  1.       <cfinput type="checkbox" name="fill2" value="1" id="fill2"> 
  2.                   Chicken &amp; Salad<br>
  3.                   <cfinput type="checkbox" name="fill2" value="2" id="fill2"> 
  4.                   Egg &amp; lettuce<br>
  5.                   <cfinput type="checkbox" name="fill2" value="3" id="fill2"> 
  6.                   Mediterranean<br>
  7.                   <cfinput type="checkbox" name="fill2" value="4" id="fill2"> 
  8.                   Chicken Caesar<br>
  9.                   <cfinput type="checkbox" name="fill2" value="5" id="fill2">
  10.                   Smoked Salmon &amp; Brie Cheese<br>
  11.                   <cfinput type="checkbox" name="fill2" value="6" id="fill2"> 
  12.                   Ham &amp; Salad<br>
  13.                   <cfinput type="checkbox" name="fill2" value="7" id="fill2"> 
  14.                   Vegetarian<br>
  15.                   <cfinput type="checkbox" name="fill2" value="8" id="fill2"> 
  16.                   Roast Beef</p>
  17.                   </div>

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Sep 3 '08

re: tracking the number of checkboxes selected


The fill2 variable will be a list containing the values of the checked checkboxes. It could be undefined if none are checked, so you should use cfparam to default to the empty string.
rcollins207's Avatar
Newbie
 
Join Date: Sep 2008
Posts: 4
#3: Sep 4 '08

re: tracking the number of checkboxes selected


thank you for the reply....
i haven't used <cfparam> yet and i will look into it now thank you but what i need to now is how do i make it that they have to select 4 no more no less how do i track how many that they have selected.
what they want is three radio buttons that determines how many fills they want (4,5,6)
and under that i have 8 checkboxes that are the fills but how many that they aloud to be selected depends on the three radiobuttuons
thanks for the help
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4: Sep 4 '08

re: tracking the number of checkboxes selected


As I said, it'll be a list, so use listlen on the form variable. Assuming you sent it as a post request, it would be form.fill2:
Expand|Select|Wrap|Line Numbers
  1. <cfif listlen(form.fill2) EQ 4>
rcollins207's Avatar
Newbie
 
Join Date: Sep 2008
Posts: 4
#5: Sep 5 '08

re: tracking the number of checkboxes selected


thanks mate that worked :) well
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#6: Sep 5 '08

re: tracking the number of checkboxes selected


You're welcome :) Glad it worked.
Reply


Similar ColdFusion bytes