0

My print function button doesn't seem to work upon clicking. The print view page does not show.

Here is the html code:

<button class = "hidden-print" id = "print-click">Print New Orders</button>

Here is the js code:

function printNewOrders(){
 window.print();
 $("#print-click").click(printNewOrders);
}
6
  • put $("#print-click").click(printNewOrders); out of the function. Commented Apr 14, 2016 at 17:02
  • the button still does not work. :( @DIEGO CARRASCAL Commented Apr 14, 2016 at 17:07
  • Please provide a minimal reproducible example. As demonstrated by the fact that the answers given to you "don't work", we need more information about your setup before we can answer your question. Commented Apr 14, 2016 at 17:08
  • @PocholoDelenelaMendoza, is the button being created dynamically? if it does you need to change the event linker (sound great like that...) from $("#print-click").click(printNewOrders); to $(document).on("click", "#print-click", printNewOrders); Commented Apr 15, 2016 at 15:38
  • jsfiddle.net/poch_MENDOZA/7uwm8sd0 i've recreated the issue here. @DIEGO CARRASCAL Commented Apr 16, 2016 at 2:24

1 Answer 1

1

Your click event won't be bound unless you call the function printNewOrders. Even though if you call it the page will be printed without user's intervention. So change your code like below,

function printNewOrders(){
 window.print();
}
$("#print-click").click(printNewOrders);

DEMO

answered Apr 14, 2016 at 17:02
Sign up to request clarification or add additional context in comments.

6 Comments

@PocholoDelenelaMendoza Check the demo attached with this answer. Did you include jquery in your page? Are you seeing any errors?
I did not include jquery. No errors as well when inspecting element. The function just does not work. Is there any more solutions?
@PocholoDelenelaMendoza $("#print-click").click(printNewOrders); This part will not work without jquery. If you want a non-jquery solution. you can use this jsfiddle.net/j8vfftpa/1
The button still does not function. The print media view still does not come out upon clicking.
@PocholoDelenelaMendoza Is your site live? Or can you reproduce your issue in a fiddle?
|

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.