Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Sign In
Not a member yet? Click here to register.

Print doesn't work

I use this code in an custom page - the page is populated with the data it's supposed to show, but the print button does not function?

any ideas why?

CodeDownload  
 <script type='text/javascript'>
 function printDiv(divName) {
 var printContents = document.getElementById(divName).innerHTML;
 var originalContents = document.body.innerHTML;
 document.body.innerHTML = printContents;
 window.print();
 document.body.innerHTML = originalContents;
 }
 </script>
<?php
$result = dbquery(
 "SELECT user_id as user_id, user_name, user_email, user_phone_mobile, user_phone_home, user_geo
 FROM ************_users // altered the correct name with *
 WHERE user_status = 0 ORDER BY user_name ASC"
 );
 echo "<div id='printableArea'>";
 if (dbrows($result)) {
while ($data = dbarray($result)) {

if (!empty($data['user_geo'])) {
$a = explode("|", $data['user_geo']); // it becomes array and it will break into 6 parts
$street1 = $a[0];
$street2 = $a[1];
$country = $a[3];
$region = $a[4];
$city = $a[5];
$zip = $a[6];
$data['user_geo'] = "$street1, $street2, $city, $region, $country, $zip";
}
echo "<div class='list-group-item'>Navn: <strong> ".$data['user_name']."</strong><br/></div> ";
echo "<div class='list-group-item'>Mail: <strong> ".$data['user_email']."</strong><br/></div> ";
echo "<div class='list-group-item'>Mobil: <strong> ".$data['user_phone_mobile']."</strong><br/></div> ";
echo "<div class='list-group-item'>Tlf.: <strong> ".$data['user_phone_home']."</strong><br/></div> ";
echo "<div class='list-group-item'>Adresse: <strong> ".$data['user_geo']."</strong><br/></div> ";
echo "<div class='list-group-item'><br/></div> ";
}
 } else {
 echo "No data in table.";
 }
echo "<input type='button' onclick='printDiv(\"printableArea\")' value='Udskriv side' /></div>";
?>

Try,

CodeDownload  
<script type='text/javascript'>
   function printDiv(divName) {
         var printContents = document.getElementById(divName).innerHTML;
         var originalContents = document.body.innerHTML;
         document.body.innerHTML = printContents;
         window.print();
         document.body.innerHTML = originalContents;
   }
</script>
 
<?php
   $result = dbquery("
   SELECT user_id as user_id, user_name, user_email, user_phone_mobile, user_phone_home, user_geo
   FROM ************_users // altered the correct name with *
   WHERE user_status = 0 ORDER BY user_name ASC"
   );

echo "<div id='printableArea'>";
   if (dbrows($result)) {
      while ($data = dbarray($result)) {

         if (!empty($data['user_geo'])) {
         $a = explode("|", $data['user_geo']); // it becomes array and it will break into 6 parts
         $street1 = $a[0];
         $street2 = $a[1];
         $country = $a[3];
         $region = $a[4];
         $city = $a[5];
         $zip = $a[6];
         $data['user_geo'] = "$street1, $street2, $city, $region, $country, $zip";
         }
   echo "<div class='list-group-item'>Navn: <strong> ".$data['user_name']."</strong><br/></div> ";
   echo "<div class='list-group-item'>Mail: <strong> ".$data['user_email']."</strong><br/></div> ";
   echo "<div class='list-group-item'>Mobil: <strong> ".$data['user_phone_mobile']."</strong><br/></div> ";
   echo "<div class='list-group-item'>Tlf.: <strong> ".$data['user_phone_home']."</strong><br/></div> ";
   echo "<div class='list-group-item'>Adresse: <strong> ".$data['user_geo']."</strong><br/></div> ";
   echo "<div class='list-group-item'><br/></div> ";
      }
   } else {
   echo "No data in table.";
}
echo "</div>";
echo "<input type='button' onclick='printDiv(\"printableArea\")' value='Udskriv side' />";
?>

I tried the code - tested it in Chrome, Opera, Firefox and Safari

neither of them worked

clicking the print button has only the mouse-over effect :-(
Try place
CodeDownload  
<script type='text/javascript'>
 function printDiv(divName) {
 var printContents = document.getElementById(divName).innerHTML;
 var originalContents = document.body.innerHTML;
 document.body.innerHTML = printContents;
 window.print();
 document.body.innerHTML = originalContents;
 }
</script>
 



Last in the file.
helmuth has replied to this - 11 months ago
tested ... but sorry to say, it made no difference - no pop up to print :-(
Thread Information
Author
Replies
5 posts
Views
856 times
Last Post
Last updated on 11 months ago
You can view all discussion threads in this forum.
You cannot set up a bounty in this discussion thread.
You can start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You can download attachments in this forum.
You cannot up or down-vote on the post in this discussion thread.
Users who participated in discussion: Falk, helmuth