in reply to passing variables from cgi to javascript

just create javascript arrays from the Perl arrays and then write a JS function that will do the neccessary onChange stuff. I can't actually see the (Perl-related) problem. You'll get in trouble if users switch Javascript off.

//JS also supports multidimensional and associative arrays: foobar = new Array(); foobar['opt1'] = new Array( 'values','of','the second','select','list' +); //...
--
http://fruiture.de

Replies are listed 'Best First'.
Re: Re: passing variables from cgi to javascript
by Anonymous Monk on Sep 18, 2002 at 19:39 UTC
    ah, okay - i don't think i phrased the question very well.

    the cgi script has to initialise the second list to empty values, so there's nothing to take from the second drop down menu. my question is really - how do i create a javascript array from a perl array?

    thanks

      That should be done like in the writeup of LTjake Re: passing variables from cgi to javascript with an additonal escaping of quotes.

      my %hash = ( opt1 => [qw/these are the options of the dynamic select box when opt1 in the first is selected/], #... ); my $js = 'var items = new Array();'. map { "items['$_'] = new Array('". join("','",map quotemeta => @{$hash{$_}}). "');" } keys %hash;
      --
      http://fruiture.de