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

#===================================================================== +========== my @titlelist; open FILE, "<$ENV{'DOCUMENT_ROOT'}/data/vault/titlelist.txt" or die $! +; @titlelist = <FILE>; close FILE; print br() x 5; print start_form( action=>'/cgi-bin/admin.pl' ); print table( {class=>'user_form'}, Tr( td( {width=>'55%'}, 'Select items' ), td( {width=>'35%'}, popup_menu( -name=>'title', -values=> +\@titlelist )), td( {width=>'10%'}, submit('add'))), Tr( td( 'Soemthign to remark on order' ), td( {colspan=>2}, textarea( -name=>'remark', -rows=>6, - +columns=>35 ))), Tr( td( 'ask for soemthing else if it snot listed on drop don +menu' ), td( textfield( -name=>'request' )), td( submit('request'))), Tr( td( a( {href=>'/cgi-bin/show.pl?name=showbook'}, font( {s +ize=>3, color=>'yellow'}, 'Change Order' ))), td( {colspan=>2}, submit( 'Order!' ))) ); print hidden(-name=>'date', -value=>$date); print hidden(-name=>'host', -value=>$host); print end_form(); print br() x 5; #===================================================================== +==========
In the aboev code when user hits the "Add" button or the "request" button i need it to get the user selection from frop down menu and store it.
Its about selecting items to place and orer list, i want the user to select many items form the drop down menu. And also to write its own if he can t find somethign from the drop down menu and then hit "Want".

How can i do it so the user hits those submits button so many times as is the amount of items he wants? Where do i have to submit the form to? to itself?

you can see how it looks if you visit my webpage at http://nikos.no-ip.org

ps. I edited it and wrote all the greek words to english ones. Also corrected spelling errors.

Replies are listed 'Best First'.
Re: How to select many times from a drop down menu in the same form
by shmem (Chancellor) on May 06, 2007 at 08:28 UTC

    That can be done using JavaScript.

    To select multiple items from a drop-down list in the same form, you have to store the selected items in another list in the form (and provide a facility to delete item from that list). Upon submit, the items in that list need to be selected, otherwise they won't make it into the CGI params. Get a book covering JavaScript, or visit one of the zillion sites covering JavaScript, listboxes and shopping carts.

    Anyways, here's how you can do that.

    I would rather use the POST method with that form.

    If you don't want to use JavaScript, you will have to use a list box with multiple select turned on (not a drop down); the third possibility is to have your users submit the form after each select, and store the selected items somewhere on the server side, e.g. in a CGI::Session object.

    update: I see you've implemented this at your server... as easy as cut-n-paste, no? But come on. Read the code before you include it, and include only as much as makes sense:

    You included the whole bunch from the line my $js = <<EOH; so you have the line

    print header(), start_html (-script => $js) ;
    in it. Which means
    • you are outputting the header twice
    • you have two <!DOCTYPE> declarations
    • you have a header and body section inside a body section

    Also, you could set the ordered-items list box to some initial width (via css), the small thingy in there just looks funny :-)

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      Thanks a zillion shmem! This is EXACTLY what i wanted and thanks again for providing to me 3 different ways of approaching thsi problem

      I will prefer the javascript way although having user to submit the form could be used even more easily as well.

      In both ways the user will have to hit same buttons, yes?

      Add button woudl ahve been used as submit button and same thing the request button right?Myabe thsi way sould be even more easy? I wont prefer the scrolling list method though because my list then gest huge and messes up table columns.
      print header( -charset=>'utf-8' ); print start_html( -script => my $js, -style=>'/data/css/style.css', -title=>'Order Project!' );
      Yes i did cut-n-paste firstly :-) cause iw as anxiosu to see if it works(it does!) but then i tried the baove code on the start of my page but in this way things dont get addeed in order list, which mean javascript aint workign properly but why? After all i do us ethe '-script'.
        print header( -charset=>'utf-8' ); print start_html( -script => my $js, -style=>'/data/css/style.css', -title=>'Order Project!' );

        Wrong. You are setting up another lexical variable $js which is empty at this point.

        You want

        my $js = <<EOH; // JavaScript here EOH print header( -charset=>'utf-8' ); print start_html( -script => $js, -style=>'/data/css/style.css', -title=>'Order Project!' );

        update: Try

        td( popup_menu( -name => 'ordered_items', -multiple => 1, -id => 'ordered_items', -style => "width: 230px;" ) ),

        --shmem

        _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                      /\_¯/(q    /
        ----------------------------  \__(m.====·.(_("always off the crowd"))."·
        ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: How to select many times from a drop down menu in the same form
by Joost (Canon) on May 05, 2007 at 14:27 UTC
      I do use firefox v2 but no onlne spell checker.
      Except that, i noticed that very signle tiem i try to post greek chars they are being displayd more badly that chinsese do....although they are encoding in utf-8, thats not my fault.
Re: How to select many times from a drop down menu in the same form
by derby (Abbot) on May 05, 2007 at 16:47 UTC

    Selecting multiple items from a popup menu is pretty much a usability nightmare ... are you sure you would prefer a scrolling_list?

    -derby
      Yes, i would prefer this way, but iam all open if you have something better to put into action :)
        scrolling list
Re: How to select many times from a drop down menu in the same form
by blazar (Canon) on May 05, 2007 at 18:48 UTC
    ps. I edited it and wrote all the greek words to english ones. Also corrected spelling errors.

    Well done, unlike in the past. I also noticed that in clpmisc you said you also asked here. Why not also vice-versa?