www.webdeveloper.com
Results 1 to 2 of 2

Thread: Javascript print

Hybrid View

  1. #1
    Join Date
    Mar 2005
    Posts
    13

    Javascript print

    Hello - fairly new to javascript - am hoping someone can help?

    I am using this script:

    Code:
    <script language="javascript">
    function printdiv(printpage)
    {
    var headstr = "<html><head><title></title></head><body>";
    var footstr = "</body>";
    var newstr = document.all.item(printpage).innerHTML;
    var oldstr = document.body.innerHTML;
    document.body.innerHTML = headstr+newstr+footstr;
    window.print();
    document.body.innerHTML = oldstr;
    return false;
    }
    </script>
    And then this HTML:
    HTML Code:
    <div id="div_print">
    <img src="service/the-original-29.95-oil-change.jpg" width="900" height="483"> </div>
    <div class="print-button">
    <span style="font-family:Arial, Helvetica, sans-serif; font-size:14px; color:#F00; font-weight:bold;">Please print this coupon and present to dealer at time of service</span><br /><br />
    <input name="b_print" type="button" class="ipt"   onClick="printdiv('div_print');" value=" Print ">
    </div><!--print-button-->
    This works exactly as I hoped. The problem arrises when I try to add a second instance, for example:

    HTML Code:
    <div id="div_print">
    <img src="service/the-original-29.95-oil-change.jpg" width="900" height="483"> </div>
    <div class="print-button">
    <span style="font-family:Arial, Helvetica, sans-serif; font-size:14px; color:#F00; font-weight:bold;">Please print this coupon and present to dealer at time of service</span><br /><br />
    <input name="b_print" type="button" class="ipt"   onClick="printdiv('div_print');" value=" Print ">
    </div><!--print-button-->
    
    <br /><br />
    
    <div id="div_print">
    <img src="service/tire-rotation.jpg" width="900" height="483"> </div>
    <div class="print-button">
    <span style="font-family:Arial, Helvetica, sans-serif; font-size:14px; color:#F00; font-weight:bold;">Please print this coupon and present to dealer at time of service</span><br /><br />
    <input name="b_print" type="button" class="ipt"   onClick="printdiv('div_print');" value=" Print ">
    </div><!--print-button-->
    No it does not work at all - both print buttons give the error: "Undefined". I was hoping to just use the same div container and just change the contents within that div.

    I appreciate any help /comments that can help me out.

    Thanks,

    Abe

  2. #2
    Join Date
    Mar 2005
    Posts
    13
    Found a solution on another board. Thanks anyways.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles