lev has asked for the wisdom of the Perl Monks concerning the following question:

Submitting 'name' in the textfield of a sign-in page opens (points 'action'to) a second frameset page. I want to pass the 'name' to one result_frame. What I have now at the top of the frameset page is:
#!/usr/bin/perl -w $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/;#Data coming in from my $buffer; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); use CGI qw/:standard/; use strict; use CGI::Carp qw(fatalsToBrowser); print header(); print "<html>"; print "<HEAD><SCRIPT LANGUAGE='JavaScript'>"; #<!-- print "var name = 'Testing'"; #$buffer print "</SCRIPT></HEAD>"; #//--> print "<FRAMESET ROWS='45%,55%'>"; print "<FRAMESET COLS = '75%,25%'>"; --------- print "</FRAMESET>"; print "</html>";
As it stands, via a js function to a button on another GO_frame of the same frameset, which assigns a textfield in the result_frame to 'parent.name', I can get 'Testing' to appear in the textfield (which I can later hide).
My problem now is to get the 'name' passed in $ENV{'REQUEST_METHOD'},i.e. $buffer into this parent variable. ($buffer needs yet some regexp to extract 'name',but for now I just want to see something of $buffer in the result_ frame textfield.)

Somewhere on the web I saw:
"If you want to assign the value to a JavaScript variable, you'd do something like (in PHP):

<SCRIPT type="text/javascript"> var counter = <?php echo $counter; ?>; </SCRIPT>
....which after evaluation (if counter was 10) should be: var counter = 10;"
WHAT'S THE EQUIVALENT OF THIS TRICK IN PERL?
Or, is there a better way to pass a variable from one page to a second frameset page such that it arrives to one particular frame of this frameset?

Replies are listed 'Best First'.
Re: assigning a parent html (js) variable to a perl (cgi input) variable
by Corion (Patriarch) on Sep 24, 2008 at 16:41 UTC

    I've already told you that when you asked the question in the chat:

    Just use variable interpolation (which likely also is available in PHP):

    print qq{ <SCRIPT type="text/javascript"> var counter = $counter; </SCRIPT> };

    See perlop about "Quotes and Quote-like Operators".

Re: assigning a parent html (js) variable to a perl (cgi input) variable
by jettero (Monsignor) on Sep 24, 2008 at 17:08 UTC
    Since you're using CGI anyway, why not use a little more of it like so:
    #!/usr/bin/perl # why would you do this? it'll just messup the CGI form processing.. +. # my $buffer; # read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); use strict; use warnings; use CGI; use CGI::Carp qw(fatalsToBrowser); my $cgi = new CGI; my $method = lc( $cgi->request_method ); # why? my $counter = 1; print $cgi->header, $cgi->start_html({ title => "My Page", script => qq(var counter=$counter)});

    I have to admit, I don't really know how to use frames. I believe you'd have to print those by hand like this (or something similar to it):

    print $cgi->header, $cgi->html( $cgi->frameset({ cols=>"75%,45%" }) );

    -Paul