JsPDF, how get javascript variable









up vote
0
down vote

favorite












This is what I would like to do:



  • I would like to print a value that is caught from an operation on some field in a form.

I have successfully used jsPDF but I am not able to send to pdf the value of the variable 'CPS', as shown in the following code error:



The error is:
Uncaught Error: Type of text must be string or Array. "undefined" is not recognized.
at Object.H.text (jspdf.min.js:1)
at demo (forweb.html:11)
at HTMLInputElement.onclick (forweb.html:46)


I am unable to find a solution everywhere.



Here is my code:



<!DOCTYPE HTML> 
<html>
<script type="text/javascript" src="jspdf.js"></script>
<script type="text/javascript" src="jspdf.min.js"></script>
<script type="text/javascript">

function demo()

var pdf = new jsPDF()
var uno_ = document.getElementById("uno").innerHTML;
pdf.text(10,10),uno_;
var due_ = document.getElementById("due").innerHTML;
pdf.text(10,20),chest;
var chest = document.getElementById("CPS").innerHTML;
pdf.text(10,30),chest;

function calcola() a_uno = document.getElementById("uno").value;
a_due = document.getElementById("due").value;
var answer =parseFloat(a_uno)+
parseFloat(a_due);
var CPS = document.getElementById('CPS');
CPS.value=answer;

</script>

<head>
<title>print result </title>
</head>
<form name="myForm">
one
<select id="uno" onchange="calcola(this.value)">
<option value="0"SELECTED>-</option>
<option value="1">1</option>
<option value="2">2</option>
</select></span>
due
<select id="due" onchange="calcola(this.value)">
<option value="0"SELECTED>-</option>
<option value="1">1</option>
<option value="2">2</option>
</select></span>

<input type="button" name="reset_form" value="Resetta Valori"
onclick="this.form.reset(); CPS.value = 0;">
CPS = <input type="button" name="CPS" id="CPS"/>

</form>
<input type="button" name="stampa" value="STAMPA" onclick="demo()">
</body>
</html>


Thanks in advance for your help - Ivan










share|improve this question



























    up vote
    0
    down vote

    favorite












    This is what I would like to do:



    • I would like to print a value that is caught from an operation on some field in a form.

    I have successfully used jsPDF but I am not able to send to pdf the value of the variable 'CPS', as shown in the following code error:



    The error is:
    Uncaught Error: Type of text must be string or Array. "undefined" is not recognized.
    at Object.H.text (jspdf.min.js:1)
    at demo (forweb.html:11)
    at HTMLInputElement.onclick (forweb.html:46)


    I am unable to find a solution everywhere.



    Here is my code:



    <!DOCTYPE HTML> 
    <html>
    <script type="text/javascript" src="jspdf.js"></script>
    <script type="text/javascript" src="jspdf.min.js"></script>
    <script type="text/javascript">

    function demo()

    var pdf = new jsPDF()
    var uno_ = document.getElementById("uno").innerHTML;
    pdf.text(10,10),uno_;
    var due_ = document.getElementById("due").innerHTML;
    pdf.text(10,20),chest;
    var chest = document.getElementById("CPS").innerHTML;
    pdf.text(10,30),chest;

    function calcola() a_uno = document.getElementById("uno").value;
    a_due = document.getElementById("due").value;
    var answer =parseFloat(a_uno)+
    parseFloat(a_due);
    var CPS = document.getElementById('CPS');
    CPS.value=answer;

    </script>

    <head>
    <title>print result </title>
    </head>
    <form name="myForm">
    one
    <select id="uno" onchange="calcola(this.value)">
    <option value="0"SELECTED>-</option>
    <option value="1">1</option>
    <option value="2">2</option>
    </select></span>
    due
    <select id="due" onchange="calcola(this.value)">
    <option value="0"SELECTED>-</option>
    <option value="1">1</option>
    <option value="2">2</option>
    </select></span>

    <input type="button" name="reset_form" value="Resetta Valori"
    onclick="this.form.reset(); CPS.value = 0;">
    CPS = <input type="button" name="CPS" id="CPS"/>

    </form>
    <input type="button" name="stampa" value="STAMPA" onclick="demo()">
    </body>
    </html>


    Thanks in advance for your help - Ivan










    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      This is what I would like to do:



      • I would like to print a value that is caught from an operation on some field in a form.

      I have successfully used jsPDF but I am not able to send to pdf the value of the variable 'CPS', as shown in the following code error:



      The error is:
      Uncaught Error: Type of text must be string or Array. "undefined" is not recognized.
      at Object.H.text (jspdf.min.js:1)
      at demo (forweb.html:11)
      at HTMLInputElement.onclick (forweb.html:46)


      I am unable to find a solution everywhere.



      Here is my code:



      <!DOCTYPE HTML> 
      <html>
      <script type="text/javascript" src="jspdf.js"></script>
      <script type="text/javascript" src="jspdf.min.js"></script>
      <script type="text/javascript">

      function demo()

      var pdf = new jsPDF()
      var uno_ = document.getElementById("uno").innerHTML;
      pdf.text(10,10),uno_;
      var due_ = document.getElementById("due").innerHTML;
      pdf.text(10,20),chest;
      var chest = document.getElementById("CPS").innerHTML;
      pdf.text(10,30),chest;

      function calcola() a_uno = document.getElementById("uno").value;
      a_due = document.getElementById("due").value;
      var answer =parseFloat(a_uno)+
      parseFloat(a_due);
      var CPS = document.getElementById('CPS');
      CPS.value=answer;

      </script>

      <head>
      <title>print result </title>
      </head>
      <form name="myForm">
      one
      <select id="uno" onchange="calcola(this.value)">
      <option value="0"SELECTED>-</option>
      <option value="1">1</option>
      <option value="2">2</option>
      </select></span>
      due
      <select id="due" onchange="calcola(this.value)">
      <option value="0"SELECTED>-</option>
      <option value="1">1</option>
      <option value="2">2</option>
      </select></span>

      <input type="button" name="reset_form" value="Resetta Valori"
      onclick="this.form.reset(); CPS.value = 0;">
      CPS = <input type="button" name="CPS" id="CPS"/>

      </form>
      <input type="button" name="stampa" value="STAMPA" onclick="demo()">
      </body>
      </html>


      Thanks in advance for your help - Ivan










      share|improve this question















      This is what I would like to do:



      • I would like to print a value that is caught from an operation on some field in a form.

      I have successfully used jsPDF but I am not able to send to pdf the value of the variable 'CPS', as shown in the following code error:



      The error is:
      Uncaught Error: Type of text must be string or Array. "undefined" is not recognized.
      at Object.H.text (jspdf.min.js:1)
      at demo (forweb.html:11)
      at HTMLInputElement.onclick (forweb.html:46)


      I am unable to find a solution everywhere.



      Here is my code:



      <!DOCTYPE HTML> 
      <html>
      <script type="text/javascript" src="jspdf.js"></script>
      <script type="text/javascript" src="jspdf.min.js"></script>
      <script type="text/javascript">

      function demo()

      var pdf = new jsPDF()
      var uno_ = document.getElementById("uno").innerHTML;
      pdf.text(10,10),uno_;
      var due_ = document.getElementById("due").innerHTML;
      pdf.text(10,20),chest;
      var chest = document.getElementById("CPS").innerHTML;
      pdf.text(10,30),chest;

      function calcola() a_uno = document.getElementById("uno").value;
      a_due = document.getElementById("due").value;
      var answer =parseFloat(a_uno)+
      parseFloat(a_due);
      var CPS = document.getElementById('CPS');
      CPS.value=answer;

      </script>

      <head>
      <title>print result </title>
      </head>
      <form name="myForm">
      one
      <select id="uno" onchange="calcola(this.value)">
      <option value="0"SELECTED>-</option>
      <option value="1">1</option>
      <option value="2">2</option>
      </select></span>
      due
      <select id="due" onchange="calcola(this.value)">
      <option value="0"SELECTED>-</option>
      <option value="1">1</option>
      <option value="2">2</option>
      </select></span>

      <input type="button" name="reset_form" value="Resetta Valori"
      onclick="this.form.reset(); CPS.value = 0;">
      CPS = <input type="button" name="CPS" id="CPS"/>

      </form>
      <input type="button" name="stampa" value="STAMPA" onclick="demo()">
      </body>
      </html>


      Thanks in advance for your help - Ivan







      javascript variables jspdf






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 5:12









      Grant Shannon

      6871615




      6871615










      asked Nov 11 at 2:09









      Ivan Togni

      12




      12






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Your demo function has errors when calling the JSPDF text function. The text function needs 3 arguments and since you closed the parenthesis after setting the position, the variable value was never sent.



          function demo() 
          var pdf = new jsPDF()
          var uno_ = document.getElementById("uno").value;
          pdf.text(10,10,uno_);
          var due_ = document.getElementById("due").value;
          pdf.text(10,20,due_);
          var chest = document.getElementById("CPS").value;
          pdf.text(10,30,chest);
          pdf.save('my.pdf');



          Here I changed innerHTML to value to show the selected value on the select tag. This might fix the error you're getting.
          I also added the save function just so you can view the result






          share|improve this answer




















          • In this way no variable is obtained and therefore printed. same error message
            – Ivan Togni
            Nov 11 at 14:25










          • I created this pen to test. See if it's working for you. If it try, try to compare your code. codepen.io/julio-oliveira-the-flexboxer/pen/oQzYdR I saw that you also used the chest variable before it was declared, so it was undefined
            – Julio Oliveira
            Nov 11 at 15:46










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245249%2fjspdf-how-get-javascript-variable%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          Your demo function has errors when calling the JSPDF text function. The text function needs 3 arguments and since you closed the parenthesis after setting the position, the variable value was never sent.



          function demo() 
          var pdf = new jsPDF()
          var uno_ = document.getElementById("uno").value;
          pdf.text(10,10,uno_);
          var due_ = document.getElementById("due").value;
          pdf.text(10,20,due_);
          var chest = document.getElementById("CPS").value;
          pdf.text(10,30,chest);
          pdf.save('my.pdf');



          Here I changed innerHTML to value to show the selected value on the select tag. This might fix the error you're getting.
          I also added the save function just so you can view the result






          share|improve this answer




















          • In this way no variable is obtained and therefore printed. same error message
            – Ivan Togni
            Nov 11 at 14:25










          • I created this pen to test. See if it's working for you. If it try, try to compare your code. codepen.io/julio-oliveira-the-flexboxer/pen/oQzYdR I saw that you also used the chest variable before it was declared, so it was undefined
            – Julio Oliveira
            Nov 11 at 15:46














          up vote
          0
          down vote













          Your demo function has errors when calling the JSPDF text function. The text function needs 3 arguments and since you closed the parenthesis after setting the position, the variable value was never sent.



          function demo() 
          var pdf = new jsPDF()
          var uno_ = document.getElementById("uno").value;
          pdf.text(10,10,uno_);
          var due_ = document.getElementById("due").value;
          pdf.text(10,20,due_);
          var chest = document.getElementById("CPS").value;
          pdf.text(10,30,chest);
          pdf.save('my.pdf');



          Here I changed innerHTML to value to show the selected value on the select tag. This might fix the error you're getting.
          I also added the save function just so you can view the result






          share|improve this answer




















          • In this way no variable is obtained and therefore printed. same error message
            – Ivan Togni
            Nov 11 at 14:25










          • I created this pen to test. See if it's working for you. If it try, try to compare your code. codepen.io/julio-oliveira-the-flexboxer/pen/oQzYdR I saw that you also used the chest variable before it was declared, so it was undefined
            – Julio Oliveira
            Nov 11 at 15:46












          up vote
          0
          down vote










          up vote
          0
          down vote









          Your demo function has errors when calling the JSPDF text function. The text function needs 3 arguments and since you closed the parenthesis after setting the position, the variable value was never sent.



          function demo() 
          var pdf = new jsPDF()
          var uno_ = document.getElementById("uno").value;
          pdf.text(10,10,uno_);
          var due_ = document.getElementById("due").value;
          pdf.text(10,20,due_);
          var chest = document.getElementById("CPS").value;
          pdf.text(10,30,chest);
          pdf.save('my.pdf');



          Here I changed innerHTML to value to show the selected value on the select tag. This might fix the error you're getting.
          I also added the save function just so you can view the result






          share|improve this answer












          Your demo function has errors when calling the JSPDF text function. The text function needs 3 arguments and since you closed the parenthesis after setting the position, the variable value was never sent.



          function demo() 
          var pdf = new jsPDF()
          var uno_ = document.getElementById("uno").value;
          pdf.text(10,10,uno_);
          var due_ = document.getElementById("due").value;
          pdf.text(10,20,due_);
          var chest = document.getElementById("CPS").value;
          pdf.text(10,30,chest);
          pdf.save('my.pdf');



          Here I changed innerHTML to value to show the selected value on the select tag. This might fix the error you're getting.
          I also added the save function just so you can view the result







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 11 at 3:30









          Julio Oliveira

          111




          111











          • In this way no variable is obtained and therefore printed. same error message
            – Ivan Togni
            Nov 11 at 14:25










          • I created this pen to test. See if it's working for you. If it try, try to compare your code. codepen.io/julio-oliveira-the-flexboxer/pen/oQzYdR I saw that you also used the chest variable before it was declared, so it was undefined
            – Julio Oliveira
            Nov 11 at 15:46
















          • In this way no variable is obtained and therefore printed. same error message
            – Ivan Togni
            Nov 11 at 14:25










          • I created this pen to test. See if it's working for you. If it try, try to compare your code. codepen.io/julio-oliveira-the-flexboxer/pen/oQzYdR I saw that you also used the chest variable before it was declared, so it was undefined
            – Julio Oliveira
            Nov 11 at 15:46















          In this way no variable is obtained and therefore printed. same error message
          – Ivan Togni
          Nov 11 at 14:25




          In this way no variable is obtained and therefore printed. same error message
          – Ivan Togni
          Nov 11 at 14:25












          I created this pen to test. See if it's working for you. If it try, try to compare your code. codepen.io/julio-oliveira-the-flexboxer/pen/oQzYdR I saw that you also used the chest variable before it was declared, so it was undefined
          – Julio Oliveira
          Nov 11 at 15:46




          I created this pen to test. See if it's working for you. If it try, try to compare your code. codepen.io/julio-oliveira-the-flexboxer/pen/oQzYdR I saw that you also used the chest variable before it was declared, so it was undefined
          – Julio Oliveira
          Nov 11 at 15:46

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245249%2fjspdf-how-get-javascript-variable%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Darth Vader #20

          How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

          Ondo