Click to See Complete Forum and Search --> : Mixing Perl and Javascript?


jinkas
10-08-2003, 04:19 PM
I'm working on developing a new available software page for my university's College of Engineering web site. To see the old version, go to http://www.cae.wisc.edu/software/index.php The test version that I'm working on, which is more dynamic, is located at http://www.cae.wisc.edu/~joneill/test/test7.php Originally myself and the other fellow on the project were going to use PHP to read the information from the database, but now we have decided to use Perl. Is it possible to read from a database using Perl, manipulate those variables read, and pass that along to the javascript located at http://www.cae.wisc.edu/~joneill/test/js/navscript.js ? For now I have hard-coded the 10 examples that are there, but this will be reading from a database with over 190 software programs. Specific data for each program needs to be passed to four different arrays in the javascript. Is it possible to do this? Thanks!

-jinkas

Charles
10-08-2003, 04:38 PM
Originally posted by jinkas
Is it possible to do this?It should be quite simple. However I do hope you aren't violating the Americans with Disabilities Act or some other accessibility law by making a site that is JavaScript dependant.

jinkas
10-08-2003, 04:44 PM
Don't worry, I'm on top of that. The page functions just as well in Lynx and Simply Web 2000 as it does in MSIE or Netscape. I'm also running it through Bobby over and over again to make sure there aren't any problems.

How would the variables be passed from the database to the javascript?

-jinkas

Charles
10-08-2003, 05:17 PM
#!user/local/bin/perl
use CGI qw(:all);
use strict;

my $foo = 'foo';

my $script = <<EOQ;
\n<!--
variable = $foo;
onload = function () {alert(foo)}
// -->
EOQ

print header, start_html ('Example'), script({-type=>'text/javascript'}, $script), end_html;

Charles
10-08-2003, 05:20 PM
Or, if you want to use Perl to generate an external script...

#!user/local/bin/perl
use CGI qw(header);
use strict;

my $foo = 'Foo';

print header (-type => 'text/javascript'), <<EOQ;
variable = $foo;
onload = function () {alert(foo)}
EOQ