Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Adding JavaScript and DHTML content in a Perl script

Posted on 2004-03-29
11
Medium Priority
?
243 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

 
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
 
LVL 12

Accepted Solution

by:
venkateshwarr earned 1200 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 800 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

618 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