Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^3: HTML::Template recalling selected dropdown options

by Thilosophy (Curate)
on May 13, 2005 at 09:33 UTC ( #456644=note: print w/replies, xml ) Need Help??

in reply to Re^2: HTML::Template recalling selected dropdown options
in thread HTML::Template recalling selected dropdown options

I've been able to make something like this work when both the value and text are the same, but not when they are different.

Okay, to do this, your Perl program needs to know about all the possible options (both values and labels). It could get these from a database or config file. Let's assume you have them like so

my $options = { 23 => 'Text One', 36 => 'Text Two', };
then you can look up the label for the current selection.

Since you have all these options in your program or database now, it is a bad idea to duplicate them in the HTML template again. And since a select group typically needs no design at all (and if so that should be CSS anyway), I am inclined to agree with Hero Zzyzzx and recommend creating the whole HTML for the select in your program (for example with and stuffing it into the template as is.

(Of course, you can also eliminate the duplication by stuffing all the options into a tmpl_loop, but, as has been pointed out, this makes your template more complex than it needs to be)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://456644]
[Discipulus]: the new spam: gdpr consensus mail
[Corion]: Yeah, but the hope is that when I just delete it I won't receive any more mail from them
[Corion]: ... a faint hope, I know
[Discipulus]: ah ah you are still so optimist, Corion ? ;=)

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2018-05-25 07:28 GMT
Find Nodes?
    Voting Booth?