Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Here is a part of a CGI. I'm trying to create HREF links on each radio group item:

print radio_group (-name => "item", -value => ["B","T","S","M"], -labels => { "B" => "Item B (\$10)", "T" => "Item T (\$50)", "S" => "Item S (\$200)", "M" => "Item M (\$500)" }, -linebreak => 1);
How do I insert html links on each item? So the user can click on, say, Item B and be taken to another link?

Peter

Replies are listed 'Best First'.
Re: Creating HREF links on radio group items
by little (Curate) on Jun 21, 2002 at 18:47 UTC

    As I do not exactly know what you are asking for I just added some links as follows. CGI.pm is your friend as always :-). So I'd suggest:

    print radio_group (-name => "item", -value => ["B","T","S","M"], -labels => { 'B' => 'Item '.a({href=>"/help/b.html";},"B").' + ($10)', 'T' => 'Item '.a({href=>"/help/b.html";},"T").' + ($50)', 'S' => 'Item '.a({href=>"/help/b.html";},"S").' + ($200)', 'M' => 'Item '.a({href=>"/help/b.html";},"M").' + ($500)' }, -linebreak => 1);
    If thats not what you've been looking for please feel free to elaborate on the task :-)


    Have a nice day
    All decision is left to your taste
    Update
    Fixed single quotes after "'Item " . Yes, just cut'n paste woes. :-)

      You'll need to undef autoEscape if you want this to work here, otherwise the labels will be the actual HTML generated by the a() method.

      autoEscape(undef); print radio_group (-name => "item", -value => ["B","T","S","M"], -labels => { 'B' => 'Item '.a({-href=>"/help/b.html"},"B").' + ($10)', 'T' => 'Item .a({-href=>"/help/b.html"},"T").' +($50)', 'S' => 'Item .a({-href=>"/help/b.html"},"S").' +($200)', 'M' => 'Item .a({-href=>"/help/b.html"},"M").' +($500)' }, -linebreak => 1); autoEscape(1);
      You'll also need to import the autoEscape method, by adding
      use CGI qw/:standard autoEscape/;

      Maybe there's a more elegant way to do this? Anyone?

      Update: Fixed syntax errors I cut-and-copied. . .

      -Any sufficiently advanced technology is
      indistinguishable from doubletalk.

        Well, ok, I didn't think so far for now :-)
        Ok and the URL's also should be the ones for the documents then and not a unique one, ok.
        But in CGI.pm's POD there seems to be no such Pragma -autoEscape, but that might be due to the fact that I read the docs on my PC where not the newest AS Perl and hence not the newest CGI.pm is installed. The docs rather say "By default, all HTML that is emitted by the form-generating functions is passed through a function called escapeHTML() ..." and "... To turn autoescaping off completely, use autoescape() ..." along with samples.

        Have a nice day
        All decision is left to your taste
        I simplified an item line,

        "B" => a({href=>"/test.html";},"B"),

        but I get the error:

        syntax error at /usr/local/apache/cgi-perl/work/script.pl line 95, at EOF

        Line 95 is the line I give above.

        Any idea why I'm getting this error?
•Re: Creating HREF links on radio group items
by merlyn (Sage) on Jun 21, 2002 at 19:04 UTC
    This was also posted <a href="news:<3d13713d.7107750@news1.on.sympatico.ca>">as a usenet article. Please don't "cross post" without declaring that you're also asking another group. It's a waste of other people's time to not declare so. You're being rude and selfish.

    -- Randal L. Schwartz, Perl hacker

      cross-posting: Posting a single copy of a Usenet article to several newsgroups at the same time by putting their names in the Newsgroups line.

      I didn't realize PerlMonks had anything to do with usenet. Sorry.
        Perlmonks doesn't have anything to do with usenet, but many monks like merlyn take the time out of their very busy days to answer questions on both. Both the perl newsgrous and perlmonks are pretty responsive, so crossposting isn't of any use.