mnicks
mnicks

Reputation: 25

Change a function from button-executed to auto-executed

I'm using the following sample code which prints locally when clicking the button, but would like it to print automatically when the page loads.

Here is the sample code:

        <script>
            $(document).ready(function () {
                $("#printBtn").click(function () {
                    //1. perform server side task
                    $.ajax({
                        url: "CreateTextFileHandler.ashx", success: function (txtFileName) {
                            alert("The text file: " + txtFileName + " was created at server side. Continue printing it...");

                            //2. Print the created text file specifying the file name

                            jsWebClientPrint.print('useDefaultPrinter=' + $('#useDefaultPrinter').attr('checked') + '&printerName=' + $('#installedPrinterName').val() + '&txtFileName=' + txtFileName);


                        }
                    });
                });
            });
        </script>

I want to change it by removing the $("#printBtn").click(function() so it will run without user intervention after the page loads. When I do the CreateTextFileHandler.ashx executes and the alert executes, but the call to jsWebClientPrint does not excecute.

Upvotes: 0

Views: 99

Answers (0)

Related Questions