The onsubmit option is the way to go:

-- test.tmpl --
<html> <head> <title>Test Page</title> <script language="javascript"> <!-- function move_opt(source, destination) { for(var i = source.length - 1; i >= 0; i--) { if (source.options[i].selected) { destination.options[destination.length] = new Option(sourc +e.options[i].text, source.options[i].value); source.options[i] = null; } } } // --> </script> <body> <form action="test.cgi" method="get" onsubmit="for(var i = 0; i < docu +ment.forms[0].box2.length; i++){document.forms[0].box2.options[i].sel +ected = 'selected'}"> <table> <tr> <td> <select name="box1" size="5" multiple="multiple"> <!-- TMPL_LOOP NAME="list" --> <option value="<!-- TMPL_VAR NAME="value" -->"><!-- TMPL_V +AR NAME="text" --></option> <!-- /TMPL_LOOP --> </select> </td> <td> <input type="button" value="->" onclick="move_opt(document.for +ms[0].box1, document.forms[0].box2);"><br /><br /> <input type="button" value="<-" onclick="move_opt(document.for +ms[0].box2, document.forms[0].box1);"> </td> <td> <select name="box2" size="5" multiple="multiple"> </select> </td> </tr> <tr> <td colspan="3" align="center"><input type="submit" value="sub +mit"></td> </tr> </table> </form> </body> </html>
-- show_test.cgi --
#!/usr/bin/perl -w use CGI; use HTML::Template; use strict; my @ref = ( { value => '1', text => 'a', }, { value => '2', text => 'b', }, { value => '3', text => 'c', }, { value => '4', text => 'd', }, { value => '5',text => 'e', }, ); my $q = new CGI; print $q->header; my $template = HTML::Template->new(filename => 'test.tmpl'); $template->param(list => \@ref); print $template->output;
-- test.cgi --
#!/usr/bin/perl -w use CGI; use strict; my $q = new CGI; print $q->header; print "$_<br>" foreach $q->param('box2');
I used method="GET" just to show the selected info in the URL.

--
Rock is dead. Long live paper and scissors!

In reply to Re: Multiple item selects and CGI.pm headaches! by LTjake
in thread Multiple item selects and CGI.pm headaches! by waswas-fng

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.