|
Radio Buttons
| [Previous] [Main] [Next] |
|
| |
| Radio buttons aren't really buttons, but appear as small circles that a user can "click" to activate a particular selection. Radio buttons differ from checkboxes in that only one selection can be active at a time. Whenever one of the radio buttons in a group is selected, all the others are automatically unselected.
| |
|
| |
| The term "radio button" refers to the pushbutton action commonly used in old car radios, where depression of one button would release all the other buttons.
| |
|
| |
| Radio buttons are represented by the htmlInputRadio class. A radio button can be initially checked or unchecked using the Check() method. The IsChecked() method allows you to test the state of an object in memory.
| |
|
| |
| Each radio button object is identified by a unique name, specified in the constructor or the Name() method. Typically, radio buttons are arranged as groups on a form allowing a user to select one of the options. The htmlInputRadioGroup class is used to assemble radio button objects sharing common attributes such as name and alignment.
| |
|
| |
| If htmlInputRadio is used independently of htmlInputRadioGroup, 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.
| |
|
| |
| htmlInputRadio objects are added to forms and htmlInputRadioGroup objects using the << insertion operator or the Add() method.
| |
|
| |
| The descriptive text displayed beside a radio button 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 radio button, and groups of radio buttons may be arranged horizontally or vertically.
| |
|
| |
| Do not confuse the value of a radio button object with it's label. The value of a radio button is a non-display string that's sent to the server when the form is submitted. For example, in a group of radio buttons representing a list of countries, the labels would be the names of the nations (e.g., "United State", "Mexico", etc.) while the values might be ordinal numbers or abbreviations. When a form containing a radio button group is submitted to a server, the value of the one selected radio button is included in the name/value pair list for the form.
| |
|
| |
|
| |
|
| |
| #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 radio button
| |
| // 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
| |
| // buttons).
| |
| htmlInputRadioGroup group( "country" ) ;
| |
| group.Align( align_right ) ;
| |
|
| |
| // The first radio button will be checked.
| |
| group << htmlInputRadio( "",
| |
| "america",
| |
| "United States of America",
| |
| STATE_CHECKED ) ;
| |
|
| |
| group << htmlInputRadio( "",
| |
| "argentina",
| |
| "Argentina" ) ;
| |
|
| |
| group << htmlInputRadio( "",
| |
| "mexico",
| |
| "Mexico" ) ;
| |
|
| |
| group << htmlInputRadio( "",
| |
| "uk",
| |
| "United Kingdom" ) ;
| |
|
| |
| // Create a form, using a script for
| |
| // the submit action.
| |
| htmlForm form( "/cgi-bin/script" ) ;
| |
|
| |
| // Insert the radio button 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 ;
| |
| }
| |
|
| |
|
| |
| <HTML>
| |
| <HEAD>
| |
| <TITLE>html++ example application</TITLE>
| |
| </HEAD>
| |
| <BODY>
| |
| <FORM ACTION="/cgi-bin/script" METHOD="POST">
| |
| <INPUT TYPE="RADIO" VALUE="america" NAME="country" CHECKED>United States of America<BR>
| |
| <INPUT TYPE="RADIO" VALUE="argentina" NAME="country">Argentina<BR>
| |
| <INPUT TYPE="RADIO" VALUE="mexico" NAME="country">Mexico<BR>
| |
| <INPUT TYPE="RADIO" VALUE="uk" NAME="country">United Kingdom<BR>
| |
| <BR>
| |
| <INPUT TYPE="SUBMIT"></FORM>
| |
| </BODY>
| |
| </HTML>
| |
|
| |
|
| |
|
| |
