NAME
"DBIx::HTML::PopupRadio" - Convert sql into a popup menu or radio group.
Synopsis
use DBIx::HTML::PopupRadio;
my($popup_object) = DBIx::HTML::PopupRadio -> new
(
dbh => $dbh,
sql => 'select campus_id, campus_name from campus order by campus_name',
);
$popup_object -> set(default => '1');
my($popup_menu) = $popup_object -> popup_menu();
my($radio_group) = $popup_object -> radio_group();
print $popup_menu;
Description
This module takes a db handle and an SQL statement, and builds a hash.
Then you ask for that hash in HTML, as a popup menu or as a radio group.
The reading of the db table is delayed until you actually call one of
the methods 'popup_menu' or 'radio_group'. Even then, it is delayed
until any parameters passed in to these 2 methods are processed.
After a call to one of these 2 methods, you can call the 'size' method
if you need to check how many rows were returned by the SQL you used.
Neither the module CGI.pm, nor any of that kidney, are used by this
module. We simply output pure HTML.
Distributions
This module is available both as a Unix-style distro (*.tgz) and an
ActiveState-style distro (*.ppd). The latter is shipped in a *.zip file.
See http://savage.net.au/Perl-modules/html/installing-a-module.html for
help on unpacking and installing each type of distro.
Usage
You create an object of the class by calling the constructor, 'new'.
You then call 'set', if you wish, to set any options.
Now call 'popup_menu' or 'radio_group' to get the HTML.
Lastly, display the HTML as part of a form.
The method names 'popup_menu' and 'radio_group' (and 'param') were
chosen to be reminiscent of methods with the same names in the CGI.pm
module. But let me repeat, my module does not use CGI.
Options
Here, in alphabetical order, are the options accepted by the
constructor, together with their default values.
dbh => ''
Pass in an open database handle.
This option is mandatory, in the call to new, set, popup_menu or
radio_group. Ie By the time you call one of the latter 2 methods,
dbh must be set.
default => ''
Pass in the string (from SQL column 2) which is to be the default
item on the popup menu or radio group. You supply here the visible
menu item, not the value associated with that menu item.
If default is not given a value, the first menu item becomes the
default.
See the discussion of the sql option for details about the menu
items.
This option is not mandatory.
javascript => ''
Pass in a string of JavaScript, eg an event handler.
By using, say, javascript => 'onChange = "replicate()"', you can
change the first line of HTML output from this: