View Full Version : Issues with printme function

10-04-2012, 05:57 PM
Hey All,

I am a complete JS novice. I recently copy/pasted this code into a WP site and it worked. Today I found that something in it is broken, but I don't know what to look for. Any help?

This code is supposed to allow someone to print a coupon by opening the coupon image in a new window and immediately open a print dialog box as well. Once the print button is clicked, it should then close the new window.

Here is a link to the specific page:

Here is the code as I have it:

<script type="text/javascript">// <![CDATA[
function makepage(src)
return "\n" +
"<head>\n" +
"\n" +
"<script>\n" +
"function step1() {\n" +
" setTimeout('step2()', 10);\n" +
"}\n" +
"function step2() {\n" +
" window.print();\n" +
" window.close();\n" +
"}\n" +
"</scr" + "ipt>\n" +
"</head>\n" +
"<body onLoad='step1()'>\n" +
"<img src='" + src + "' />\n" +
"</body>\n" +
<div _mce_tmp="1">
function printme(evt)
if (!evt) {
// Old IE
evt = window.event;
var image = evt.target;
if (!image) {
// Old IE
image = window.event.srcElement;
src = "http://www.annie-mac.com/wp-content/uploads/2012/07/Appraisal-Credit-Cropped.jpg";
link = "about:blank";
var pw = window.open(link, "_new");
// ]]></script>

<h1>Residential-Appraisal Credit</h1>
Please print this coupon and either keep it, donate it or give it away to someone you know who may be buying or refinancing their home. This coupon must be presented to your Holmdel Branch AnnieMac Loan Officer at the time of your application for validation. This promotion is only available through AnnieMac’s Holmdel, NJ Branch 732-526-8000 opt 3. You will be assigned a registration number at the time of application or you can register your coupon by starting the application process by clicking the “Apply now” from this web page. You are under no obligation and there is no cost to pre-approve you. </br>

<strong>Print Coupon</strong>

*<img onclick="printme(event)" src="http://www.annie-mac.com/wp-content/uploads/2012/07/printButton-small-blue.png" alt="" />

<a><img class="aligncenter size-full wp-image-2980" title="Appraisal Credit" src="http://www.annie-mac.com/wp-content/uploads/2012/07/Appraisal-Credit-Cropped.jpg" alt="Appraisal Credit" width="640" height="276" /></a>

<b>You have JavaScript turned off.</b> Please right-click the image and select "Save As...", open it in your favorite picture viewer and print.
<strong>Print Coupon</strong>

*<img onclick="printme(event)" src="http://www.annie-mac.com/wp-content/uploads/2012/07/printButton-small-blue.png" alt="" />

I found these errors in the Chrome console:

Uncaught SyntaxError: Unexpected token < residential-appraisal-credit:323

3Uncaught ReferenceError: printme is not defined residential-appraisal-credit:348

Uncaught ReferenceError: printme is not defined residential-appraisal-credit:357

Logic Ali
10-04-2012, 06:23 PM
Firefox is more explicit in this case:

SyntaxError: syntax error


(line 323, col 1)

10-04-2012, 09:03 PM
Thank you, Logic Ali. I have gotten it working once again.