--- Tim Howell <[EMAIL PROTECTED]> wrote:
> This isn't strictly a CGI::App question, but I know that a lot of us
> are
> using HTML::Template, so here goes: is there a good way to set the
> initial value in an HTML select using HTML::Template parameters?
> I've
> got a select with 100 options (integers 0-100), and I'm looking for a
> simple way to populate it from the DB that's driving this app.
Consider letting the user type a value in to a text field and
validating the value instead of having a drop down with 101 options.
Thats just too long and will not make it easy for users.
If you decide that validating is too much for you then do this:
In your perl code create an array of hashtables with a two entries in
each hashtable. The value and a variable to denote if the value is
selected. Use one for a selected variable and zero if the variable is
not selected. The following pseudo-code should point you in the right
direction.
# create an array of hashtables with "value" set over your range
my @arr;
for my $val (1..100) {
push { value => $val, selected => ($val eq $selected_val) }, @arr;
}
$template->param( range_0_100 => @arr );
in HTML code add all the values using the loop directive.
<select>
<!-- TMPL_LOOP NAME="range_0_100" -->
<option name="<!-- TMPL_VAR NAME=value -->"
<!-- TMPL_IF NAME="selected" -->selected<!-- /TMPL_IF -->
>
<!-- /TMPL_LOOP -->
</select>
-john
PS This code has not been tested.
>
> Ideas?
>
> Thanks! =)
>
> --TWH
>
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/[EMAIL PROTECTED]/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]