CodeKit HTML Select Element Methods

[Code Descriptions] [Index] [Code Sets] ## CodeKit HTML Select Element Methods These methods return a string containing HTML code for various types of select boxes. Deprecated codes are not offered as new user choices but are displayed if already selected in the data. If the data contains codes for which there is no code value the raw data values are displayed. Submitting a form without making changes will always will keep the data unchanged whether or not the code descriptions exist and whether or not the selections are deprecated. ### Common Options Each of the select methods takes a single standard parameter: the code set. Extra options can be passed in as name - value pairs. The following four options are common to all of the HTML select methods. Here is an example using all of them:
    # PHP
    print $codekit->select('day', array(
                            'var_name' => 'start_day',
                            'value'    => $start_day,
                            'default'  => 1,
                            'subset'   => array( 1, 2, 3, 4, 5 ),
                            'options'  => 'onchange="submit()"'
                            ));
    # Perl
    print $codekit->select('day',
                            var_name => 'start_day',
                            value    => $start_day,
                            default  => 1,
                            subset   => [ 1, 2, 3, 4, 5 ],
                            options  => 'onchange="submit()"'
                            );
    # HTML
    <select name="start_day" onchange="submit()">
    <option value="1" selected>Monday
    <option value="2">Tuesday
    <option value="3">Wednesday
    <option value="4">Thursday
    <option value="5">Friday
    </select>
#### 'var_name' => 'start_day' The HTML select methods all declare a form variable name which will hold the value(s) that the user selects. 'var_name' defaults to $code_set. For example, a select element displaying 'day' code set choices will by default return the user selection in the 'day' variable. In the example above the programmer has specified that the user selection will be returned in the 'start_day' form variable. Multi-value select elements will return the selected values in an array variable. For example, a "select multiple" element will by default return multiple user day selections in the 'day[]' variable. Specify multivalue form variable names *without* the '[]' at the end. For example, specify 'sick_days' instead of 'sick_days[]'. #### 'value' => $start_day If you specify a 'value' option, that value will always be used. Select multiple value methods will expect 'value' to be an array. If a 'value' parameter is not passed in, CodeKit looks at the incoming form variable for the value to use. In PHP, the value is found like this:
    $value = $_POST ? $_POST[$var_name] : $_GET[$var_name];
Perl gives the programmer control over the parsing of the GET and POST information. As a result, it is the programmer's responsibility to tell CodeKit how to get those values. See the Perl Handle Creation page to see how this is done. Or simply pass the value using the 'value' option. #### 'default' => 1 If no 'value' is specified, and no value is found in the incoming form variable, then CodeKit will use any optional 'default' value specified. In the example above the default is the code for Monday. #### 'subset' => $show_these_codes It is sometimes the case that we only want to display a subset of all possible codes for the user to select from. In the example above we constrain the user choices to the codes for Monday - Friday and return the choice in the 'start_day' form variable. #### 'options' => 'onchange="submit()"' You can select select options using the optional 'options' option. Separate multiple options with spaces. ### HTML Select Single Value Methods The following two single value HTML select methods accept the common options listed above plus some method specific options. #### select()
    # PHP
    $html = $codekit->select($code_set, array(
                              'select_prompt' => 'Code set description?',
                              'blank_prompt'  => 'None'
                              ));
    # Perl
    $html = $codekit->select($code_set,
                              select_prompt => 'Code set description?',
                              blank_prompt  => 'None'
                              );
select() prepares a "drop down" HTML select element for user selection of a single value. 'select_prompt' is the name to show if there is no initial selection. It defaults to the code set description and a question mark. 'blank_prompt' is the name to show to blank out a selection. If none is provided it is not possible for the user to blank out an initial selection. #### radio()
    # PHP
    $html = $codekit->radio($code_set, array(
                             'sep'          => "<br>\n",
                             'blank_prompt' => 'None'
                             ));
    # Perl
    $html = $codekit->radio($code_set,
                             sep          => "<br>\n",
                             blank_prompt => 'None'
                             );
radio() prepares HTML radio box elements for user selection of a single value. 'blank_prompt' is the name to show to blank out a selection. If none is provided it is not possible for the user to blank out an initial selection. 'sep' is the string to insert between radiobox elements. It defaults to "<br>\n". ### HTML Select Multiple Value Methods The following two multiple value HTML select methods accept the common options listed above some method specific options. These accept and produce multiple values so do not forget to pass in an array value. #### multiple()
    # PHP
    $html = $codekit->multiple($code_set, array(
                                'size' => 10
                                ));
    # Perl
    $html = $codekit->multiple($code_set,
                                size => 10
                                );
multiple() prepares a select multiple HTML element. 'size' is optional and gives the maximum number of elements to scroll. #### checkbox()
    # PHP
    $html = $codekit->checkbox($code_set, array(
                                'sep' => "<br>\n"
                                ));
    # Perl
    $html = $codekit->checkbox($code_set,
                                sep => "<br>\n"
                                );
checkbox() prepares multiple checkbox elements for multiple user selections. 'sep' is the string to insert between checkbox elements. It defaults to "<br>\n". [Code Descriptions] [Index] [Code Sets]