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

helmuth - Latest reply on 27-10-2018 07:19 by helmuth

0

helmuth
helmuth
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?

 <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>";
?>

Sort replies by

0

Falk
Falk
Try,

<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' />";
?>

0

helmuth
helmuth
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 :-(

0

Falk
Falk
Try place
<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 - 2 months ago

0

helmuth
helmuth
tested ... but sorry to say, it made no difference - no pop up to print :-(
Actions
You can view all discussion threads in this forum.
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.
Forum Tags
Participated Users
Users who participated in discussion: :
helmuth, Falk

Moderators:
{%user_avatar%}

print doesn't work
by {%user_profile_link%} {%post_date%}