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;

In reply to Re: Re: Re: How do you pass a perl variable to a Javascript function by Anonymous Monk
in thread How do you pass a perl variable to a Javascript function by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.