<?php
$edit_data      = $this->db->get_where('prescription', array('prescription_id' => $param2))->result_array();
foreach ($edit_data as $row):
$patient_info   = $this->db->get_where('patient' , array('patient_id' => $row['patient_id'] ))->result_array();
?>
    <div id="prescription_print">
        <table width="100%" border="0">
            <tr>
                <td align="left" valign="top">
                    <?php foreach ($patient_info as $row2){ ?>
                        <?php echo 'Patient Name: '.$row2['name']; ?><br>
                        <?php echo 'Age: '.$row2['age']; ?><br>
                        <?php echo 'Sex: '.$row2['sex']; ?><br>
                    <?php } ?>
                </td>
                <td align="right" valign="top">
                    <?php $name = $this->db->get_where('doctor' , array('doctor_id' => $row['doctor_id'] ))->row()->name;
                          echo 'Doctor Name: '.$name;?><br>
                    <?php echo 'Date: '.date("d M, Y", $row['timestamp']); ?><br>
                    <?php echo 'Time: '.date("H:i", $row['timestamp']); ?><br>
                </td>
            </tr>
        </table>
        <hr>
        <div class="row">
            <div class="col-md-12">

                <div class="panel panel-primary" data-collapsed="0">

                    <div class="panel-body">

                        <b><?php echo get_phrase('case_history'); ?> :</b>

                        <p><?php echo $row['case_history']; ?></p>

                        <hr>

                        <b><?php echo get_phrase('medication'); ?> :</b>

                        <p><?php echo $row['medication']; ?></p>

                        <hr>

                        <b><?php echo get_phrase('note'); ?> :</b>

                        <p><?php echo $row['note']; ?></p>

                    </div>

                </div>

            </div>
        </div>
    </div>
    <br>

    <a onClick="PrintElem('#prescription_print')" class="btn btn-primary btn-icon icon-left hidden-print">
        Print Prescription
        <i class="entypo-doc-text"></i>
    </a>
<?php endforeach; ?>



<script type="text/javascript">

    function PrintElem(elem)
    {
        Popup($(elem).html());
    }

    function Popup(data)
    {
        var mywindow = window.open('', 'prescription', 'height=400,width=600');
        mywindow.document.write('<html><head><title>Prescription</title>');
        mywindow.document.write('<link rel="stylesheet" href="assets/css/neon-theme.css" type="text/css" />');
        mywindow.document.write('<link rel="stylesheet" href="assets/js/datatables/responsive/css/datatables.responsive.css" type="text/css" />');
        mywindow.document.write('</head><body >');
        mywindow.document.write(data);
        mywindow.document.write('</body></html>');

        mywindow.print();
        mywindow.close();

        return true;
    }

</script>

Dani AI

Generated

A short, practical troubleshooting checklist for the print problem reported by (and prompted by /): the most common causes are JavaScript errors that stop execution, the print code running before the DOM is ready, pop‑up blocking, stylesheet paths failing inside the new window, or print CSS hiding the element that should be printed. Verifying those items will usually reveal the root cause quickly.

Key checks (perform them in order):

  • Open the browser console and look for errors (syntax, Uncaught ReferenceError, or $ is not defined).
  • Confirm the print function is actually called (insert console.log or a breakpoint).
  • Ensure the page has jQuery (if $ is used) and that the print script runs after that library and after the DOM (use DOMContentLoaded or jQuery(function(){...})).
  • If window.open returns null, a popup blocker is preventing the print window—allow popups or use an in‑page print approach.
  • Use absolute URLs when adding styles to the print window (relative paths can fail); call document.close() and focus() on the new window before invoking print().
  • Check print CSS rules (or framework classes like “hidden/hidden-print”) that might hide the content during printing.

A concise, robust pattern to open a print window (adapt as needed):

function printSectionById(id) {
  var el = document.getElementById(id);
  if (!el) { console.error('print element not found:', id); return; }

  var w = window.open('', '_blank');
  if (!w) { console.error('popup blocked'); return; }

  var html = '<!doctype html><html><head><meta charset="utf-8"><title>Print</title>';
  html += '<link rel="stylesheet" href="'+location.origin+'/assets/css/neon-theme.css">';
  html += '</head><body>' + el.innerHTML + '</body></html>';

  w.document.open();
  w.document.write(html);
  w.document.close();
  w.focus();
  w.onload = function(){ w.print(); w.close(); };
}

If popups are undesirable, use a print stylesheet and call window.print() from the main page; a simple @media print that hides everything except the target element avoids opening new windows and sidesteps popup blockers.

Recommended Answers

All 4 Replies

anyone help me :)

maybe if you tell what isn't working

pzuurveen javascript functions are not working

functions are not working

It would be more helpful if you stated what is supposed to happen, and what doesn't happen. "It's not working" is too vague for any question.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.