Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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:

    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

  • #2
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Firefox is more explicit in this case:
    SyntaxError: syntax error


    }</div>

    (line 323, col 1)


  • Users who have thanked Logic Ali for this post:

    gbrinkert (10-04-2012)

  • #3
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you, Logic Ali. I have gotten it working once again.


  •  

    Tags for this Thread

    Posting Permissions

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