Solved

Adding JavaScript and DHTML content in a Perl script

Posted on 2004-03-29
11
225 Views
Last Modified: 2013-12-25
My database.pl looks like this

use warnings;
use strict;    
use DBI;      
      
         my $dbh = DBI->connect( 'xxx',
                                 'xxx',
                                 'xxx',  ) || die "Database connection not made: $DBI::errstr\n";
                             
          my $sql=qq{  SELECT count(*) FROM Table };                            
                 
         
         my $sth = $dbh->prepare ($sql)|| die "Prepare failed: $DBI::errstr\n";
         
         $sth->execute() || die "Couldn't execute query:$DBI::errstr\n";

       print "Content-Type: text/html\n\n";
      print "<html><body>";
      print "<BODY leftmargin=0 topmargin=0>";
      print "<table height=\"100%\" width = \"100%\" cellpadding = \"0\" cellspacing = \"0\" border = \"2\" align =       \"center\">";
      print "<tr height=\"5%\">";
      print "<td align = \"center\" colspan =\"2\" bgColor=\"blue\">";
      print "<FONT face=\"Times New Roman\" size=\"5.5\"> OUTPUT </font>";
      print "</td>";
      print "</tr>";
      print "<tr height=\"90%\">";
      print "<td width = \"100%\" colspan = \"2\">";
      
                #####################################################################
                   INSERT CODE HERE

                #####################################################################
      print "<table align=\"center\" bgcolor=\"lightblue\" border=2 bordercolor=\"maroon\" >";
      
      print "<tr>";
      print"<br>";
      print "<td><b>TABLE</b></td>";
      print "</tr>";
      while (my @row= $sth_A->fetchrow_array())
              {
             print "<tr>\n";
             foreach my $my_td (@row) { print "<td>$my_td</td>\n"; }
             print "</tr>\n";
             
            }
      print "</table>";
      print "<br>";
              
         $sth->finish();                                            
         $dbh->disconnect() || die "Failed to disconnect\n";  
       
         print "<tr height=\"5%\">";
      print "<td align = \"center\" colspan =\"2\" bgColor=\"blue\">&nbsp;</td>";
      print "</tr>";
      print "</table>";
      print "</body></html>";
      
----------------------------------------------------------------------------------------------------------------------------------------------

And I need to insert the following code into the area in the above script where its written  INSERT HERE !!!!!!!!!!

the code is follwing

<html>
<head>
<style>
      body{font-family:arial;}
      table{font-size:80%;background:maroon}
      a{color:black;text-decoration:none;font:bold}
      a:hover{color:#black}
      td.menu{background:#f5deb3}
      table.menu
      {
      font-size:100%;
      position:absolute;
      visibility:hidden;
      }
</style>
<script type="text/javascript">
      function showmenu(elmnt)
      {
      document.all(elmnt).style.visibility="visible"
      }
      function hidemenu(elmnt)
      {
      document.all(elmnt).style.visibility="hidden"
      }
</script>
</head>
      
<body>
      <table width="14%">
       <tr bgcolor="#FF8080">
        <td onmouseover="showmenu('Home')" onmouseout="hidemenu('home')">
         <b>Home</b><br />
         <table class="menu" id="accueil" width="100%">
         <tr><td class="menu"><a href="http://localhost/cgi-bin/page1.html">Page1</a></td></tr>
         <tr><td class="menu"><a href="http://localhost/cgi-bin/page2.html">Page 2</a></td></tr>
         <tr><td class="menu"><a href="http://localhost/cgi-bin/page3.html">Page 3</a></td></tr>
         </table>
        </td>
         </tr>
</table>
</body>
</html>

---------------------------------------------------------------------------------------------------------------------------------------------
Any suggestions ?
best regrds

0
Comment
Question by:ronan_40060
  • 4
  • 4
  • 3
11 Comments
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10706236
This should work...

#####################################################################
print <<DHTML;

<html>
<head>
<style>
     body{font-family:arial;}
     table{font-size:80%;background:maroon}
     a{color:black;text-decoration:none;font:bold}
     a:hover{color:#black}
     td.menu{background:#f5deb3}
     table.menu
     {
     font-size:100%;
     position:absolute;
     visibility:hidden;
     }
</style>
<script type="text/javascript">
     function showmenu(elmnt)
     {
     document.all(elmnt).style.visibility="visible"
     }
     function hidemenu(elmnt)
     {
     document.all(elmnt).style.visibility="hidden"
     }
</script>
</head>
     
<body>
     <table width="14%">
      <tr bgcolor="#FF8080">
       <td onmouseover="showmenu('Home')" onmouseout="hidemenu('home')">
        <b>Home</b><br />
        <table class="menu" id="accueil" width="100%">
        <tr><td class="menu"><a href="http://localhost/cgi-bin/page1.html">Page1</a></td></tr>
        <tr><td class="menu"><a href="http://localhost/cgi-bin/page2.html">Page 2</a></td></tr>
        <tr><td class="menu"><a href="http://localhost/cgi-bin/page3.html">Page 3</a></td></tr>
        </table>
       </td>
        </tr>
</table>
</body>
</html>


DHTML
#####################################################################
0
 
LVL 9

Author Comment

by:ronan_40060
ID: 10706747
thanks but there is alread print "<head>" and <body> in the perl scrip
writing javascrip and DHtml code starting with print <<DHTML; and ending with ????
0
 
LVL 3

Expert Comment

by:rkosai
ID: 10706773
Looking over your script, you may also be interested in the HTML::Template module as a better alternative.  It allows for code separation by placing the HTML in one file, with loop commands, and the actual Perl script in another file.

Because you're obviously interested in following "best practices," (you've used "strict" and "warnings") this code separation allows for easier maintenance for your script by non-perl people (don't have to worry about $ signs, etc.), and is usually recommended for HTML-heavy scripts such as the one shown.

Documentation for this script is available at: http://search.cpan.org/~samtregar/HTML-Template-2.6/Template.pm
0
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10707942

>>but there is alread print "<head>" and <body> in the perl script

ronan_40060,

Do you want include html files dynamically?
If not just include the script tags and table tag...
Are you getting any errors??

venkat.
0
 
LVL 9

Author Comment

by:ronan_40060
ID: 10708348
Hello Venkat
I did not get this  what you said   Do you want include html files dynamically??
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 12

Accepted Solution

by:
venkateshwarr earned 300 total points
ID: 10709109
I meant something like this......


use warnings;
use strict;    
use DBI;      
     
         my $dbh = DBI->connect( 'xxx',
                                 'xxx',
                                 'xxx',  ) || die "Database connection not made: $DBI::errstr\n";
                             
         my $sql=qq{  SELECT count(*) FROM Table };                        
                 
         
         my $sth = $dbh->prepare ($sql)|| die "Prepare failed: $DBI::errstr\n";
         
         $sth->execute() || die "Couldn't execute query:$DBI::errstr\n";

      print "Content-Type: text/html\n\n";
     print "<html><body>";
     print "<BODY leftmargin=0 topmargin=0>";
     print "<table height=\"100%\" width = \"100%\" cellpadding = \"0\" cellspacing = \"0\" border = \"2\" align =      \"center\">";
     print "<tr height=\"5%\">";
     print "<td align = \"center\" colspan =\"2\" bgColor=\"blue\">";
     print "<FONT face=\"Times New Roman\" size=\"5.5\"> OUTPUT </font>";
     print "</td>";
     print "</tr>";
     print "<tr height=\"90%\">";
     print "<td width = \"100%\" colspan = \"2\">";
     
                #####################################################################
                ##  CODE INSERTED

print <<DHTML;

<style>
     body{font-family:arial;}
     table{font-size:80%;background:maroon}
     a{color:black;text-decoration:none;font:bold}
     a:hover{color:#black}
     td.menu{background:#f5deb3}
     table.menu
     {
     font-size:100%;
     position:absolute;
     visibility:hidden;
     }
</style>
<script type="text/javascript">
     function showmenu(elmnt)
     {
     document.all(elmnt).style.visibility="visible"
     }
     function hidemenu(elmnt)
     {
     document.all(elmnt).style.visibility="hidden"
     }
</script>
     
     <table width="14%">
      <tr bgcolor="#FF8080">
       <td onmouseover="showmenu('Home')" onmouseout="hidemenu('home')">
        <b>Home</b><br />
        <table class="menu" id="accueil" width="100%">
        <tr><td class="menu"><a href="http://localhost/cgi-bin/page1.html">Page1</a></td></tr>
        <tr><td class="menu"><a href="http://localhost/cgi-bin/page2.html">Page 2</a></td></tr>
        <tr><td class="menu"><a href="http://localhost/cgi-bin/page3.html">Page 3</a></td></tr>
        </table>
       </td>
        </tr>
</table>

DHTML

                #####################################################################
     print "<table align=\"center\" bgcolor=\"lightblue\" border=2 bordercolor=\"maroon\" >";
     
     print "<tr>";
     print"<br>";
     print "<td><b>TABLE</b></td>";
     print "</tr>";
     while (my @row= $sth_A->fetchrow_array())
            {
           print "<tr>\n";
           foreach my $my_td (@row) { print "<td>$my_td</td>\n"; }
           print "</tr>\n";
           
          }
     print "</table>";
     print "<br>";
             
         $sth->finish();                                            
         $dbh->disconnect() || die "Failed to disconnect\n";  
       
         print "<tr height=\"5%\">";
     print "<td align = \"center\" colspan =\"2\" bgColor=\"blue\">&nbsp;</td>";
     print "</tr>";
     print "</table>";
     print "</body></html>";
0
 
LVL 9

Author Comment

by:ronan_40060
ID: 10714134
Hello Venkat
Im getting a nasty error like Can't find string terminator "EOF" anywhere before EOF at print <<DHTML;
I tried evrything but still I am getting the error, dont know why
there is no space after DHTML still I get this error :(:(:
0
 
LVL 3

Assisted Solution

by:rkosai
rkosai earned 200 total points
ID: 10714570
Ronan, there are three things that you could do:

First, if you are running this script on a different platform that you are coding on, you'll want to make sure you're uploading the script in ASCII mode, not Binary mode.

Second, try making
print<<DHTML;
into
print<<"DHTML";


Third, if all else fails, you can always use the q modifier.  Replace "print<<DHTML;" with "print q{" and the DHTML marker with "};"

So it look like:
print q{
<style>
     body{font-family:arial;}
     table{font-size:80%;background:maroon}
     a{color:black;text-decoration:none;font:bold}
     #All the other code inside the DHTML print
};
0
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10716463

There could be two reasons,

1. there is an exrta space somewhere like
"print <<    DHTML;"

2. the termination of print has space like this...
   
   DTML

it should be

DHTML
0
 
LVL 9

Author Comment

by:ronan_40060
ID: 10716467
hello rkosai
thanks for the help
I did try out print<<"DHTML";   but it did not work and im running the script on the same platform so the only chance for me now is to use print q instead
just go thruouh the code below and correct me if I made any mistake

use warnings;
use strict;    
use DBI;      
     
         my $dbh = DBI->connect( 'xxx',
                                 'xxx',
                                 'xxx',  ) || die "Database connection not made: $DBI::errstr\n";
                             
         my $sql=qq{  SELECT count(*) FROM Table };                        
                 
         
         my $sth = $dbh->prepare ($sql)|| die "Prepare failed: $DBI::errstr\n";
         
         $sth->execute() || die "Couldn't execute query:$DBI::errstr\n";

      print "Content-Type: text/html\n\n";
     print "<html><body>";
     print "<BODY leftmargin=0 topmargin=0>";
     print "<table height=\"100%\" width = \"100%\" cellpadding = \"0\" cellspacing = \"0\" border = \"2\" align =      \"center\">";
     print "<tr height=\"5%\">";
     print "<td align = \"center\" colspan =\"2\" bgColor=\"blue\">";
     print "<FONT face=\"Times New Roman\" size=\"5.5\"> OUTPUT </font>";
     print "</td>";
     print "</tr>";
     print "<tr height=\"90%\">";
     print "<td width = \"100%\" colspan = \"2\">";
     
               

print q {


<style>
     body{font-family:arial;}
     table{font-size:80%;background:maroon}
     a{color:black;text-decoration:none;font:bold}
     a:hover{color:#black}
     td.menu{background:#f5deb3}
     table.menu
     {
     font-size:100%;
     position:absolute;
     visibility:hidden;
     }
</style>
<script type="text/javascript">
     function showmenu(elmnt)
     {
     document.all(elmnt).style.visibility="visible"
     }
     function hidemenu(elmnt)
     {
     document.all(elmnt).style.visibility="hidden"
     }
</script>
     
     <table width="14%">
      <tr bgcolor="#FF8080">
       <td onmouseover="showmenu('Home')" onmouseout="hidemenu('home')">
        <b>Home</b><br />
        <table class="menu" id="accueil" width="100%">
        <tr><td class="menu"><a href="http://localhost/cgi-bin/page1.html">Page1</a></td></tr>
        <tr><td class="menu"><a href="http://localhost/cgi-bin/page2.html">Page 2</a></td></tr>
        <tr><td class="menu"><a href="http://localhost/cgi-bin/page3.html">Page 3</a></td></tr>
        </table>
       </td>
        </tr>
</table>

};

     print "<table align=\"center\" bgcolor=\"lightblue\" border=2 bordercolor=\"maroon\" >";
     
     print "<tr>";
     print"<br>";
     print "<td><b>TABLE</b></td>";
     print "</tr>";
     while (my @row= $sth_A->fetchrow_array())
            {
           print "<tr>\n";
           foreach my $my_td (@row) { print "<td>$my_td</td>\n"; }
           print "</tr>\n";
           
          }
     print "</table>";
     print "<br>";
             
         $sth->finish();                                            
         $dbh->disconnect() || die "Failed to disconnect\n";  
       
         print "<tr height=\"5%\">";
     print "<td align = \"center\" colspan =\"2\" bgColor=\"blue\">&nbsp;</td>";
     print "</tr>";
     print "</table>";
     print "</body></html>";
0
 
LVL 3

Expert Comment

by:rkosai
ID: 10720972
The script looks fine as you posted it.  Are you having any problems?
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Ever wondered how to display how many visitors you have online. In this tutorial I will show you an easy but effective way to display the number of online visitors in WhizBase. In this article I assume you have read my previous articles and know …
In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now