Solved

Adding JavaScript and DHTML content in a Perl script

Posted on 2004-03-29
11
226 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to silent print from safari browser 6 170
After Effects Random Number, but different each time 5 91
Google  (Get  Users Email) 2 100
Need sample Angular apps for study 4 71
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

914 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

16 Experts available now in Live!

Get 1:1 Help Now