Adding Check boxes to a form
| 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'. Syntax for Check boxes: ColdFusion: <input name="favorite" type="checkbox" value="coldfusion"> |
| form1.cfm |
|
< form action="form2.cfm" method="post" name="form1">First Name: <input name="first_name" type="text" size="20" maxlength="20">< br>Last Name: <input name="last_name" type="text" size="20" maxlength="20">< br>Man: <input name="m_f_value" type="radio" value="Man" checked>Female <input name="m_f_value" type="radio" value="Female">< br>< select name="country"> <option value="Afghanistan">Afghanistan</option> <option value="Albania">Albania</option> <option value="Bahamas">Bahamas</option> <option value="Belgium">Belgium</option> <option value="Canada">Canada</option> <option value="China" selected>China</option></ select>< br>What is your favorite? < br>ColdFusion: <input name="favorite" type="checkbox" value="coldfusion"><br>PHP: <input name="favorite" type="checkbox" value="php"><br>ASP: <input name="favorite" type="checkbox" value="asp"><br>< input name="upload_person" type="submit" id="upload_person" value="Submit -->"></ form> |
| form2.cfm |
|
First Name: <cfoutput>#Form.first_name#</cfoutput>< br>Last Name: <cfoutput>#Form.last_name#</cfoutput>< br><!--- test radio buttons ---> < cfswitch expression = "#Form.m_f_value#"> <cfcase value="Man">You are a man. </cfcase> <cfcase value="Female">You are a female. </cfcase></ cfswitch>< br>Country: <cfoutput>#Form.country#</cfoutput>< br><!--- test check boxes ---> < cfif NOT isDefined("Form.favorite")>No favorite programming language selected. <cfelse>Your favorite programming language is: <br> <cfif listContains("#Form.favorite#","coldfusion")>Coldfusion <br> </cfif> <cfif listContains("#Form.favorite#","php")>PHP <br> </cfif> <cfif listContains("#Form.favorite#","asp")>ASP </cfif></ cfif> |
For more information about check boxes, see this tutorial.
Advertisement
No User Comments.
No User Comments, be the first one to write your comments?


