I find it works pretty well using TMPL_LOOP and an array of hashref's
from the db - I loop through the data array and set the 'Selected'
item before passing into the template, like so:
in the viewer module:
my $product_types = $self-dbh-selectall_arrayref(select * from
product_type where ONIX_Code like 'B%', { Slice = {} });
if ($data-{ProductTypeID}) {
foreach my $row (@$product_types) {
$row-{Selected} = 'selected' if $row-{ProductTypeID} eq
$data-{ProductTypeID};
}
}
$template-params(product_types = $product_types);
in the template:
select class=inputbox name=ProductTypeID
TMPL_LOOP NAME=product_types
option value=TMPL_VAR NAME=ProductTypeID TMPL_VAR
NAME=SelectedTMPL_VAR NAME=ONIX_Code : TMPL_VAR
NAME=ProductType/option
/TMPL_LOOP
/select
TMPL_VAR NAME=err_ProductTypeID
mike
On 14 April 2010 22:52, Adam a...@spatialsystems.org wrote:
I want to have a dropdown menu that shows years 2000 thru 2015. I'm using
HTML::Template and I know I can pass an array ref to HTML::Template and loop
over it to make the menu, but how would I put in a selected year? What's
the best method?
# CGI::Application community mailing list
####
## To unsubscribe, or change your message delivery options, ##
## visit: http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
## Web archive: http://www.erlbaum.net/pipermail/cgiapp/ ##
## Wiki: http://cgiapp.erlbaum.net/ ##
####