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

Hello Monks,

I am trying to pass a variable ($linux_host) from a CGI script(Master.cgi) to another CGI script(test.cgi) using java script as below-

"<a href=javascript: onClick=window.open('/cgi-bin/test.cgi?host=$li +nux_host','TEST','width=600,height=600')>Reboot</a>"
and am able to access the variable in 2nd CGI script (test.cgi) which is a popup window requires user to enter the userid & submit the form.

But when the form is submitted i am not able to access the host name. How can i retain(access) the host variable which is passed from 1st script(Master.cgi)

Regards, SS

Replies are listed 'Best First'.
Re: Getting Variable value after submitting cgi form
by almut (Canon) on Jun 09, 2009 at 10:16 UTC
    How can i retain(access) the host variable...

    One way would be to put it in a hidden field of the form when you generate the 2nd CGI script's output.

      Hi, As advised i used the hidden field, still am not able to access the server/host name. Please check the following code snippet.
      ========================== ## FILE: test.cgi ## use CGI::Pretty qw( :html3 :standard ); my $cgi = new CGI; print $cgi->header, $cgi->start_html('Submit User id'); print $head; print start_form(); my $host = $cgi->param('host'); print "<font color=green> Please Enter the UserID for $host: </font>"; print $cgi->text_field('USER','',10); print "\t\t".submit('action','Submit'); $cgi->hidden( -name=>'server', -value => $cgi->param('host')); if (param()) { my $test= $cgi->param('action'); if( $cgi->param('action') eq 'Submit') { my $server = $cgi->param('server'); my $user_id = $cgi->param('USER'); print "UserID: $user_id and HOST: $server " ; } } print endform; ## END of HTML form print end_html;

        From your top node:

        ... test.cgi?host=$linux_host ...

        In your script:

        ... my $server = $cgi->param('server'); ... print "UserID: $user_id and HOST: $server " ;

        You will need to make sure you use consistent names everywhere.