Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: HTML::Template recalling selected dropdown options

by Thilosophy (Curate)
on May 12, 2005 at 03:37 UTC ( #456226=note: print w/replies, xml ) Need Help??


in reply to HTML::Template recalling selected dropdown options

There is a discussion about this on the CGI::App wiki.

I like to duplicate the current selection on top of the list:

<select name="templates" id="templates"> <tmpl_if selected> <option value="<tmpl_var selected>"> <tmpl_var selected_text> </opt +ion> <option disabled>---------</option> <tmpl_else> <option value="">Select...</option> </tmpl_if> <option value="23>">Text one</option> <option value="36>">Text two</option> </select>

Replies are listed 'Best First'.
Re^2: HTML::Template recalling selected dropdown options
by bradcathey (Prior) on May 12, 2005 at 12:29 UTC

    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. Do you have a piece of Perl that can show me how you populate the params? Thanks


    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot
      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 CGI.pm) 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://456226]
help
Chatterbox?
[chacham]: I'm sure this is old, but i just came across it: If you put a million monkeys at a million keyboards, one of them will eventually write a Java program. The rest of them will write Perl programs.
[LanX]: lol
[Corion]: Woo hoo! A new Auralnauts episode!
LanX mean unfair and funny
[LanX]: but most java code looks like from one million monkey using eclipse. ..
[Eily]: ah yes, perl's motto, There Is More Than One Monkey Typing It

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2018-04-23 16:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?