javascriptjqueryprintthis

How to use input box values in PrintThis plugins footer


$(document).on("click", "#btnPrin9t", function(e) {
  // e.preventDefault();
  // e.stopPropagation();
  $("#table, #txtW, #txtAt").printThis({
    debug: false, // show the iframe for debugging
    importCSS: true, // import page CSS
    importStyle: true, // import style tags
    printContainer: true, // grab outer container as well as the contents of the selector
    loadCSS: "", // path to additional css file - use an array [] for multiple
    pageTitle: "", // add title to print page
    removeInline: true, // remove all inline styles from print elements
    printDelay: 0, // variable print delay; depending on complexity a higher value may be necessary
    base: true,
    header: "",
    footer: "<br>Total in Words:'"
    $('#txtWord').val()
    "'", // prefix to html
    formValues: true // preserve input/form values
  });
});

I want to print input box value using footer. I can use print click as shown first line but for some adjustment. I want to use in footer can anyone help.


Solution

  • For concatenating a string in javascript we use +

    So instead of this:

    "<br>Total in Words:'"$('#txtWord').val()"'"
    

    try:

    "<br>Total in Words:'"+$('#txtWord').val()+"'"
    

    So your code will be like this:

     $(document).on("click", "#btnPrin9t", function (e) {
       // e.preventDefault();
      // e.stopPropagation();
      $("#table, #txtW, #txtAt").printThis({
        debug: false, // show the iframe for debugging
        importCSS: true, // import page CSS
        importStyle: true, // import style tags
        printContainer: true, // grab outer container as well as the contents of the selector
        loadCSS: "", // path to additional css file - use an array [] for multiple
        pageTitle: "", // add title to print page
        removeInline: true, // remove all inline styles from print elements
        printDelay: 0, // variable print delay; depending on complexity a higher value may be necessary
        base: true,
        header: "",
        footer: "<br>Total in Words:'"+$('#txtWord').val()+"'", // prefix to html
        formValues: true            // preserve input/form values
      });
    });