Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running Javascript in CGI

Status
Not open for further replies.

Fayeby

Programmer
Sep 16, 2002
7
CH
I am very new to the following: Programming, Perl, CGI's and Javascript. Hence I have a very big problem on my hands!

I am trying to get the submit buttons on this page to display a confirm "are you sure?" when clicked but I cannot get the Javascript bit to work. If you comment it out then the page will run but as soon as I put it back in I get an internal server error.

Any ideas would be greatly appreciated.

Faye

Here's my CGI:
#!/app/perl5005/bin/perl

# Ensure that Perl can see the DBI module...
push (@INC, $ENV{'WORKFLOW_PATH'} . "/lib/site_perl");

use DBI;
use CGI;
require "CDA_CGI.pl";

$ENV{'ORACLE_HOME'} = "/app/oracle/product/client/8.1.7";
$ENV{'TNS_ADMIN'} = "/var/opt/oracle";


$q = new CGI;

$EnvironmentName = $q -> param ('EnvironmentName') or &CGIError ("'EnvironmentName' not defined.");
$AttributeGroup = $q -> param ('AttributeGroup') or &CGIError ("'AttributeGroup' not defined.");


{
local ($/) = undef;
open (HTMLFILE, "templates/db_env_deployments.html") or &CGIError ("Unable to open 'db_env_deployments.html': $!");
$HTML = <HTMLFILE>;
close (HTMLFILE);

$DBDetailsFile = &quot;/home/fwimpenn/.dtl_details&quot;;
open (DB_DETAILS, $DBDetailsFile) or &CGIError (&quot;Unable to open '$DBDetailsFile': $!&quot;);
$DETAIL_LINE = <DB_DETAILS>;
close (DB_DETAILS);
}



chomp ($DETAIL_LINE);
($CodeLoaderDB, $Username, $Password) = split (/\s+/, $DETAIL_LINE);

$dbh = DBI -> connect (&quot;DBI:Oracle:$CodeLoaderDB&quot;, $Username, $Password) or &CGIError (&quot;Unable to connect to Database: &quot;);

$DBAttributes = $dbh -> prepare (&quot;
select key, value
from code_loader.environment_attr
where attribute_group_name = '$AttributeGroup'
and environment_name = '$EnvironmentName'
order by key&quot; );

$DBAttributes -> execute ();

#$FORM_TEXT = &quot;Content-type: text/html\n\n&quot;;

#$FORM_TEXT .= &quot;<script LANGUAGE=\&quot;JavaScript\&quot;>\n&quot;;
#$FORM_TEXT .= &quot;<!--\n&quot;;
#$FORM_TEXT .= &quot;//This function allows the user to have a 'confirm' message displayed\n&quot;;
#$FORM_TEXT .= &quot;//before following the desired link.\n&quot;;
#$FORM_TEXT .= &quot;function confirmSubmit(message)
#$FORM_TEXT .= &quot;{\n&quot;;
#$FORM_TEXT .= &quot;var agree = confirm(message)\n&quot;;
#$FORM_TEXT .= &quot;if (agree)\n&quot;;
#$FORM_TEXT .= &quot;return true\n&quot;;
#$FORM_TEXT .= &quot;else\n&quot;;
#$FORM_TEXT .= &quot;return false\n&quot;;
#$FORM_TEXT .= &quot;}&quot;
#$FORM_TEXT .= &quot;</Script>\n&quot;;
#
#$FORM_TEXT .= &quot;<FORM NAME=\&quot;ModifyAttributes\&quot; ACTION=\&quot;/cgi-bin/maintain_environment_attribute.cgi\&quot; onSubmit=\&quot;return confirmSubmit('Are you sure you want to deploy this component?\&quot;>\n&quot;;
#$FORM_TEXT .= &quot;<table border=\&quot;1\&quot; height=\&quot;34\&quot;>\n&quot;;

while (@COLUMNS = $DBAttributes -> fetchrow ())
{
($Key, $Value )= @COLUMNS;


$FORM_TEXT .= &quot;<INPUT TYPE=\&quot;HIDDEN\&quot; NAME=\&quot;Key\&quot; VALUE=\&quot;$Key\&quot;>&quot;;
$FORM_TEXT .= &quot;<INPUT TYPE=\&quot;HIDDEN\&quot; NAME=\&quot;EnvironmentName\&quot; VALUE=\&quot;$EnvironmentName\&quot;>&quot;;
$FORM_TEXT .= &quot;<INPUT TYPE=\&quot;HIDDEN\&quot; NAME=\&quot;AttributeGroup\&quot; VALUE=\&quot;$AttributeGroup\&quot;>&quot;;

$FORM_TEXT .= &quot;<td width=\&quot;20%\&quot;height=\&quot;25\&quot;>$Key</td>\n&quot;;
$FORM_TEXT .= &quot;<td width=\&quot;50%\&quot;height=\&quot;25\&quot;><input type=\&quot;text\&quot; name=\&quot;Value\&quot; size=\&quot;30\&quot; value=\&quot;$Value\&quot;></td>\n&quot;;
$FORM_TEXT .= &quot;<td width=\&quot;15%\&quot;height=\&quot;25\&quot;><input type=\&quot;submit\&quot; size=\&quot;50\&quot; value=\&quot; Modify \&quot; name=\&quot;Modify\&quot;></td>\n&quot;;
$FORM_TEXT .= &quot;<td width=\&quot;15%\&quot;height=\&quot;25\&quot;><input type=\&quot;submit\&quot; size=\&quot;50\&quot; value=\&quot;Remove\&quot; name=\&quot;Remove\&quot;></td>\n&quot;;
$FORM_TEXT .= &quot;</form>\n&quot;;
$FORM_TEXT .= &quot;</TR>\n&quot;;


}


$FORM_TEXT .= &quot;</table>\n&quot;;


$dbh -> disconnect ();

$HTML =~ s/XXX001/$FORM_TEXT/g;
$HTML =~ s/XXX002/$EnvironmentName/g;

print $q -> header (),
$HTML;

 
I have actually managed to solve this problem now.

Thaks to everyone that took a look.

Faye

Here is the up and running CGI:
#!/app/perl5005/bin/perl

# Ensure that Perl can see the DBI module...
push (@INC, $ENV{'WORKFLOW_PATH'} . &quot;/lib/site_perl&quot;);

use DBI;
use CGI;
require &quot;CDA_CGI.pl&quot;;

$ENV{'ORACLE_HOME'} = &quot;/app/oracle/product/client/8.1.7&quot;;
$ENV{'TNS_ADMIN'} = &quot;/var/opt/oracle&quot;;


$q = new CGI;

$EnvironmentName = $q -> param ('EnvironmentName') or &CGIError (&quot;'EnvironmentName' not defined.&quot;);
$AttributeGroup = $q -> param ('AttributeGroup') or &CGIError (&quot;'AttributeGroup' not defined.&quot;);


{
local ($/) = undef;
open (HTMLFILE, &quot;templates/db_env_deployments.html&quot;) or &CGIError (&quot;Unable to open 'db_env_deployments.html': $!&quot;);
$HTML = <HTMLFILE>;
close (HTMLFILE);

$DBDetailsFile = &quot;/home/fwimpenn/.dtl_details&quot;;
open (DB_DETAILS, $DBDetailsFile) or &CGIError (&quot;Unable to open '$DBDetailsFile': $!&quot;);
$DETAIL_LINE = <DB_DETAILS>;
close (DB_DETAILS);
}



chomp ($DETAIL_LINE);
($CodeLoaderDB, $Username, $Password) = split (/\s+/, $DETAIL_LINE);

$dbh = DBI -> connect (&quot;DBI:Oracle:$CodeLoaderDB&quot;, $Username, $Password) or &CGIError (&quot;Unable to connect to Database: &quot;);

$DBAttributes = $dbh -> prepare (&quot;
select key, value
from code_loader.environment_attr
where attribute_group_name = '$AttributeGroup'
and environment_name = '$EnvironmentName'
order by key&quot; );

$DBAttributes -> execute ();

$FORM_TEXT .= &quot;<script LANGUAGE=\&quot;JavaScript\&quot;>\n&quot;;
$FORM_TEXT .= &quot;function confirmSubmit(message)\n&quot;;
$FORM_TEXT .= &quot;{\n&quot;;
$FORM_TEXT .= &quot;var agree = confirm(message)\n&quot;;
$FORM_TEXT .= &quot;if (agree)\n&quot;;
$FORM_TEXT .= &quot;return true\n&quot;;
$FORM_TEXT .= &quot;else\n&quot;;
$FORM_TEXT .= &quot;return false\n&quot;;
$FORM_TEXT .= &quot;}\n&quot;;
$FORM_TEXT .= &quot;</Script>\n&quot;;

$FORM_TEXT .= &quot;<table border=\&quot;1\&quot; height=\&quot;34\&quot;>\n&quot;;

while (@COLUMNS = $DBAttributes -> fetchrow ())
{
($Key, $Value )= @COLUMNS;

$FORM_TEXT .= &quot;<FORM NAME=\&quot;ModifyAttributes\&quot; \n&quot;;
$FORM_TEXT .= &quot; ACTION=\&quot;/cgi-bin/maintain_environment_attribute.cgi\&quot; \n&quot;;
$FORM_TEXT .= &quot; onSubmit=\&quot;return confirmSubmit('Are you sure ?')\&quot;>\n&quot;;


$FORM_TEXT .= &quot;<INPUT TYPE=\&quot;HIDDEN\&quot; NAME=\&quot;Key\&quot; VALUE=\&quot;$Key\&quot;>&quot;;
$FORM_TEXT .= &quot;<INPUT TYPE=\&quot;HIDDEN\&quot; NAME=\&quot;EnvironmentName\&quot; VALUE=\&quot;$EnvironmentName\&quot;>&quot;;
$FORM_TEXT .= &quot;<INPUT TYPE=\&quot;HIDDEN\&quot; NAME=\&quot;AttributeGroup\&quot; VALUE=\&quot;$AttributeGroup\&quot;>&quot;;

$FORM_TEXT .= &quot;<td width=\&quot;20%\&quot;height=\&quot;25\&quot;>$Key</td>\n&quot;;
$FORM_TEXT .= &quot;<td width=\&quot;50%\&quot;height=\&quot;25\&quot;><input type=\&quot;text\&quot; name=\&quot;Value\&quot; size=\&quot;30\&quot; value=\&quot;$Value\&quot;></td>\n&quot;;
$FORM_TEXT .= &quot;<td width=\&quot;15%\&quot;height=\&quot;25\&quot;><input type=\&quot;submit\&quot; size=\&quot;50\&quot; value=\&quot; Modify \&quot; name=\&quot;Modify\&quot;></td>\n&quot;;
$FORM_TEXT .= &quot;<td width=\&quot;15%\&quot;height=\&quot;25\&quot;><input type=\&quot;submit\&quot; size=\&quot;50\&quot; value=\&quot;Remove\&quot; name=\&quot;Remove\&quot;></td>\n&quot;;
$FORM_TEXT .= &quot;</form>\n&quot;;
$FORM_TEXT .= &quot;</TR>\n&quot;;
}


$FORM_TEXT .= &quot;</table>\n&quot;;


$dbh -> disconnect ();

$HTML =~ s/XXX001/$FORM_TEXT/g;
$HTML =~ s/XXX002/$EnvironmentName/g;

print $q -> header (),
$HTML;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top