ForumClient-Side DevelopmentJavaScript Javascript print+ Reply to Thread Results 1 to 1 of 1
Thread: Javascript print
Thread Tools
Search Thread
Rate This Thread
Display
Today 10:11 PM #1 abu117
Registered User
Join Date
Mar 2005
Posts
8
Javascript print
Hello - fairly new to javascript - am hoping someone can help?
I am using this script:
Code:
And then this HTML: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>
HTML Code:
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-->
HTML Code:
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.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-->
I appreciate any help /comments that can help me out.
Thanks,
Abe


Reply With Quote

Bookmarks