|
Checkboxes
| [Previous] [Main] [Next] |
|
| |
| Checkboxes are small squares that a user can "click" to toggle a checkmark on or off, and appear to the left or right of descriptive text called a label. Checkboxes are represented by the htmlInputCheckBox class. Checkboxes can be initially checked or unchecked using the Check() method. The IsChecked() method allows you to test the state of a checkbox object in memory.
| |
|
| |
| Each checkbox object is identified by a unique name, specified in the constructor or the Name() method. Typically, checkboxes are arranged as groups on a form allowing a user to select one or more options. The htmlInputCheckBoxGroup class is used to assemble checkbox objects sharing common attributes such as name, alignment, and initial state (checked or unchecked). An entire group of checkboxes can be checked or unchecked at once using the Check() method of htmlInputCheckBoxGroup.
| |
|
| |
| If htmlInputCheckBox is used independently of htmlInputCheckBoxGroup, you must specify a name for the control to identify it on a form. Otherwise, you can leave the name argument of the constructor as an empty ("") string and the object will assume the name of the group to which it belongs.
| |
|
| |
| htmlInputCheckBox objects are added to forms and htmlInputCheckBoxGroup objects using the << insertion operator or the Add() method.
| |
|
| |
| The descriptive text displayed beside a checkbox is called it's "label", and is specified using the Label() method or a constructor argument. Labels may be aligned to the left or right of a checkbox, and groups of checkboxes may be arranged horizontally or vertically.
| |
|
| |
| Do not confuse the value of a checkbox object with it's label. The value of a checkbox is a non-display string that's sent to the server when the form is submitted. For example, in a group of checkboxes representing a list of states, the labels would be the names of the states (e.g., "Kentucky", "Illinois", etc.) while the values might be ordinal numbers or abbreviations.
| |
|
| |
|
| |
|
| |
| #include <stdio.h>
| |
| #include <stdlib.h>
| |
| #include <dcmicro/htmlpp/htmlpp.h>
| |
|
| |
| int main( void )
| |
| {
| |
| htmlCgi server ;
| |
| htmlPage page( "html++ example application" ) ;
| |
|
| |
| // Create a group to store the checkbox objects.
| |
| // Each object with use the name "country" and
| |
| // will be right aligned (i.e., the text labels
| |
| // will be to the right of the checkboxes).
| |
| htmlInputCheckBoxGroup group( "country" ) ;
| |
| group.Align( align_right ) ;
| |
|
| |
| // The first checkbox will be checked.
| |
| group << htmlInputCheckBox( "",
| |
| "america",
| |
| "United States of America",
| |
| STATE_CHECKED ) ;
| |
|
| |
| group << htmlInputCheckBox( "",
| |
| "argentina",
| |
| "Argentina" ) ;
| |
|
| |
| group << htmlInputCheckBox( "",
| |
| "mexico",
| |
| "Mexico" ) ;
| |
|
| |
| group << htmlInputCheckBox( "",
| |
| "uk",
| |
| "United Kingdom" ) ;
| |
|
| |
| // Create a form, using a script for
| |
| // the submit action.
| |
| htmlForm form( "/cgi-bin/script" ) ;
| |
|
| |
| // Insert the checkbox group and a submit
| |
| // button into the form.
| |
| form << group
| |
| << htmlBreak()
| |
| << htmlInputSubmit() ;
| |
|
| |
| // Insert the form into the page, then
| |
| // output the page.
| |
| page << form ;
| |
|
| |
| server << page ;
| |
| return 0 ;
| |
| }
| |
|
| |
|
| |
| Content-Type: text/html
| |
| <HTML>
| |
| <HEAD>
| |
| <TITLE>html++ example application</TITLE>
| |
| </HEAD>
| |
| <BODY>
| |
| <FORM ACTION="/cgi-bin/script" METHOD="POST">
| |
| <INPUT TYPE="CHECKBOX" VALUE="america" CHECKED NAME="country">United States of America<BR>
| |
| <INPUT TYPE="CHECKBOX" VALUE="argentina" NAME="country">Argentina<BR>
| |
| <INPUT TYPE="CHECKBOX" VALUE="mexico" NAME="country">Mexico<BR>
| |
| <INPUT TYPE="CHECKBOX" VALUE="uk" NAME="country">United Kingdom<BR>
| |
| <BR>
| |
| <INPUT TYPE="SUBMIT"></FORM>
| |
| </BODY>
| |
| </HTML>
| |
|
| |
|
| |
|
| |
