[cgiapp] Dropdown Menu
Mark Fuller
azfuller at gmail.com
Wed Apr 14 18:52:16 EDT 2010
On Wed, Apr 14, 2010 at 2:52 PM, Adam <adam at 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?
I struggled with this when I first began using H::T. You need to add a
"selected" hash item to the array ref. As you build the array ref, you
have to ask "if current-year equal form-year, set selected = 1."
Then, in your template you have to put inside the tmpl-loop, a
<option <tmpl-if name=selected>
selected="selected"</tmpl-if>><tmpl-var name=value></option>
(I may have made a few typos in that example.).
I thought this was unintuitive compared to how intuitive C::A and H::T
are. It seemed like there should be a better way. But, after I got
used to it, I obsessed about bigger and better things.
I've never used fillnform. That might be a good suggestion. But, I
wanted to make sure you know how to do it naively.
Mark
More information about the cgiapp
mailing list