Check boxes
A group of related check boxes is created using a series of input tags with the same name. Related check boxes don't need the multiple select fields.
There are several ways to test a group of related check boxes, this is one of them:
Here we first test if any of the check boxes is checked by using 'isDefined'.
Then we find out how many check boxes have been checked by using 'listLen'.
Finely we are testing each check box using 'listContains'.
Example code:
| <!--- check_boxes.cfm ---> <form method="post" action="test_check_boxes.cfm"> <input name="fovorite_pet" type="checkbox" value="pig">Pig<br> <input name="fovorite_pet" type="checkbox" value="bird">Bird<br> <input name="fovorite_pet" type="checkbox" value="fish">Fish<br> <input name="fovorite_pet" type="checkbox" value="cat">Cat<br> <input name="fovorite_pet" type="checkbox" value="dog">Dog <br> <input name="fovorite_pet" type="checkbox" value="rabbit">Rabbit <br> <input name="submit_button" type="submit"> </form> |
| <!--- test_check_boxes.cfm ---> <cfif NOT isDefined("Form.fovorite_pet")> No favorite pets are selected. <cfelse> You have <cfoutput>#listLen(Form.fovorite_pet)#</cfoutput> favorite pets, they are: <cfif listContains("#Form.fovorite_pet#","pig")> Pig </cfif> <cfif listContains("#Form.fovorite_pet#","bird")> Bird </cfif> <cfif listContains("#Form.fovorite_pet#","fish")> Fish </cfif> <cfif listContains("#Form.fovorite_pet#","cat")> Cat </cfif> <cfif listContains("#Form.fovorite_pet#","dog")> Dog </cfif> <cfif listContains("#Form.fovorite_pet#","rabbit")> Rabbit </cfif> </cfif> |
Advertisement
No User Comments.
No User Comments, be the first one to write your comments?

