My solution...

my $q=Query("select key, description from tablename");
while (my $ref=$q->fetchrow_hashref) {
    $ref->{selected}=1 if ($ref->{key} == $default_value)
    push @list, $ref;
}
.
.
then pass \@list as a parameter to the template
# (I have a custom Query routine which handles caching of DB data etc)

then in HTML...

<select name=dropdown>
<tmpl_loop name=list>
<option value="<tmpl_var name=key>" <tmpl_if
selected>selected</tmpl_if>><tmpl_var name=description>
</tmpl_loop>
</select>

Cheers..hope this helps!

P



On Tue, 15 Jan 2002, Simon Crute
wrote:

> Hi all.
>   I'm using HTML::Template to build some <option>, which works fine. But, I
> can't seem to figure out a quick way to set pump SELECTED into the correct
> <option> without having to completely parse the list for each request. Since
> most of these <option> lists are generated from a database, and I'll be
> making my scripts persistent via CGI::Fast, It seems silly to have to read
> the entire list just to set the SELECTED flag on one item.
> 
> Is there a better way to do this that  I'm missing ?
> 
> 
> 
> --
> Simon Crute
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to