Parvez, You can't directly access your %hash in perl from your javascript, like you're trying to do.
You have to print out the hash in a perl loop within your print "javascript" perl code. Something like this more or less... ======== #!/usr/bin/perl my $count = 0; print <<JS; <script language="javascript" type="text/javascript"> var some_array = new Array(); JS foreach my $key (sort keys %hash) { print <<JS; array[$count] = '$hash{$key}'; JS $count++; } print <<JS; finish your javascript JS more perl code here ======= --- Parvez Pathan <[EMAIL PROTECTED]> wrote: > Hi All, > I have a small CGI script which creates a small > hash. I want to retrieve values from the hash in > javascript. > > A snippet of my code is as follows: > <CODE> > use CGI; > my $q = new CGI; > print $q->header; > print qq[<body> > <form name='myForm'> > ]; > my %hash = qw ( > ONE 1 > TWO 2 > THREE 3 > ); > > print qq[<select name='sel' onChange=populate()>]; > foreach my $key (keys %hash) { > print qq[<option value='$key'>$key</option>]; > } > print qq[</select>]; > > print qq[<input type='submit' value='Go'> > </form> > </body>]; > > print qq[<script language='javascript'> > function populate () { > with (document.myForm) { > var str = > > sel.options[sel.options.selectedIndex].value; > alert (str); // will show ONE, or > TWO.... > > // Now I want to retreve value for the str > selected > var num = '$hash{str}'; > // I have even tried.. > // var num = 'hash{'+str+'}; > } > } > </script> > </html> > ]; > > </CODE> > > > Can Anyone please point out how to retrieve the hash > values so I can print 1,2,3.. > > > Thanks in advance, > Parvez > > > > > > > ____________________________________________________________ > Find what you are looking for with the Lycos Yellow > Pages > http://r.lycos.com/r/yp_emailfooter/http://yellowpages.lycos.com/default.asp?SRC=lycos10 > _______________________________________________ > Perl-Unix-Users mailing list > [EMAIL PROTECTED] > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ===== Anthony Ettinger [EMAIL PROTECTED] http://www.apwebdesign.com Instant Messengers: 1) yahoo im: apwebdesign 2) aol im: apwebdesignxl 3) msn im: [EMAIL PROTECTED] 4) icq im: 659139 __________________________________ Do you Yahoo!? Get better spam protection with Yahoo! Mail. http://antispam.yahoo.com/tools _______________________________________________ Perl-Unix-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs