Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^6: Getting all values from a CGI list box

by pKai (Priest)
on Jan 02, 2007 at 21:56 UTC ( [id://592653]=note: print w/replies, xml ) Need Help??


in reply to Re^5: Getting all values from a CGI list box
in thread Getting all values from a CGI list box

But javascript is not needed.

The following works for me, fully escaping all binary stuff in the value array, just using CGI (and URI::Escape for serialization as proposed by you)

#!perl use strict; use CGI; use URI::Escape; my $cgi = new CGI; my $i = 0; my @Values = map { uri_escape pack('c', $i++) } 1..10; my %Labels = map {$_, "Label$_"} @Values; my $size = @Values - 1; my $attr = 'listbox'; my @rightParams = ( -class=>'writeField', -name=>$attr, -values=>\@Values, -size=>$size, -multiple=>'true', -labels=>\%Labels, ); my @selected = $cgi->param($attr); my @all = $cgi->param('theValues'); print $cgi->header(), $cgi->start_html(-title=>$attr), $cgi->start_form(), $cgi->scrolling_list(@rightParams), $cgi->p('all (from hidden field): ', join(q(, ), @all)), $cgi->hidden(-name=>'theValues', -default=>\@Values), $cgi->p('you selected: ', join(q(, ), @selected)), $cgi->submit(), $cgi->end_form(), $cgi->end_html(), ;

Deserialize with uri_unescape as needed.

Replies are listed 'Best First'.
Re^7: Getting all values from a CGI list box
by ikegami (Patriarch) on Jan 02, 2007 at 22:31 UTC

    I think you missed this bit of the OP:

    The values displayed in the list box are being changed dynamically via JavaScript.

    Your code will return the initial contents of the list box, not the content changed by JavaScript as desired by the OP.

    (By the way, why are you're using a hidden field and not the session to send data from the script to a future invocation of itself?)

      As long as only

      The values displayed in the list box...

      (emphasis mine) are affected, which I read as corresponding to the values %Labels, I should be fine...

      But nitpicking aside, you are right, I did miss that bit and it's probable consequences for the server accessability of the stuff to give back.

      why are you're using a hidden field and not the session to send data from the script

      It enabled me to present a minimal working example, without introducing another (not already mentioned) module.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://592653]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2024-04-25 19:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found