in reply to Re: How do you pass a perl variable to a Javascript function
in thread How do you pass a perl variable to a Javascript function

I suspect it is a bit worse than that. Seems like maybe that is just a static html page, that he/she expects to have the value for $time magically placed in.?? That's the impression I got anyway.

But anyway, as Roger says, you may need to come up with some code and then paste it here.

Regards
Gerard

Replies are listed 'Best First'.
Re: Re: Re: How do you pass a perl variable to a Javascript function
by Anonymous Monk on Dec 12, 2003 at 18:54 UTC
    Thanks for the feedback folks. BTW: My name is David.
    MORE BACKGROUND:
    I have a form in an html page that collects 3 variables. The perl script below uses those variables. I set $try = $FORM_DATA{'fresh'} below, which is the integer variable I want to use in the perl library libprint.pl.
    #!/usr/bin/perl require "libcgi13.pl"; #library from lesson10 require "libprint.pl"; #print/refresh output &parse_input; &print_header; $MAXSAVE = 20; flock("gdata.txt",2); open(FROMFILE,"<gdata.txt"); while(<FROMFILE>){ push(@everyline, $_); } $longstring = join("",@everyline); @oldentries = split(/<!--NEWENTRY-->/,$longstring); if(@oldentries + 1 >= $MAXSAVE){ pop(@oldentries); } close(FROMFILE); open(TOFILE,">gdata.txt"); seek(TOFILE,0,0); print TOFILE "<!--NEWENTRY-->"; print TOFILE "<font face=arial><b> $FORM_DATA{'name'}: </b>"; print TOFILE " $FORM_DATA{'comments'} </font><br>\n"; shift(@oldentries); foreach $entry (@oldentries) { print TOFILE "<!--NEWENTRY-->"; print TOFILE $entry; } truncate(TOFILE, tell(TOFILE)); close(TOFILE); flock("gdata.txt",8); open(TOFILE,">ctime.txt"); print TOFILE " $FORM_DATA{'fresh'}"; close(TOFILE); $try = $FORM_DATA{'fresh'}; &print_entry();
    Now, in libprint.pl (below), I am able to print the integer variable $try (i.e. I know it's there). However, my problem is how do I get a perl variable passed to a javascript function? I've tried passing the value a number of ways but so far I've been unsuccessful.
    #!/usr/bin/perl sub print_entry { open(TIMEFILE,"<ctime.txt"); while(<TIMEFILE>){ push(@time, $_); } close(TIMEFILE); open(FROMFILE,"<gdata.txt"); print <<ENDHEADER; <head><title>D-Spot Chat Line</title> <script language=javascript> function callrefresh(try){ //time = $time[0]; time = try; millisec = parseInt(time*1000); setTimeout('refresh()',millisec); } function refresh(){ this.location.href = "cout.pl"; } </script> </head> <body bgcolor=dcdcdc onload=callrefresh($try);> <center><font face=Tahoma> <h2>Chat Lounge $try </h2> </font> </center> ENDHEADER while (<FROMFILE>) { print; } close(FROMFILE); } return 1;