Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-04-2012, 04:57 PM   PM User | #1
gbrinkert
New to the CF scene

 
Join Date: Oct 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
gbrinkert is an unknown quantity at this point
Issues with printme function

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:
http://www.annie-mac.com/residential-appraisal-credit

Here is the code as I have it:
Code:
<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" +
    "\n";
}</div>
<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");
  pw.document.open();
  pw.document.write(makepage(src));
  pw.document.close();
}
// ]]></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>

<noscript>
<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.
</noscript>
</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="" />

I found these errors in the Chrome console:

Quote:
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
gbrinkert is offline   Reply With Quote
Old 10-04-2012, 05:23 PM   PM User | #2
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 959
Thanks: 0
Thanked 198 Times in 193 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
Firefox is more explicit in this case:
Quote:
SyntaxError: syntax error


}</div>

(line 323, col 1)

Logic Ali is offline   Reply With Quote
Users who have thanked Logic Ali for this post:
gbrinkert (10-04-2012)
Old 10-04-2012, 08:03 PM   PM User | #3
gbrinkert
New to the CF scene

 
Join Date: Oct 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
gbrinkert is an unknown quantity at this point
Thank you, Logic Ali. I have gotten it working once again.
gbrinkert is offline   Reply With Quote
Reply

Bookmarks

Tags
error, function, javascript, printme, reference

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:25 AM.


Advertisement
Log in to turn off these ads.