How to fix onclick "not defined"

I want to use a button to call a function using onclick.

I kept getting the error "Uncaught ReferenceError: Mathproblems is not defined".

function Mathproblems() {
  var max = document.getElementById("max").value;
  var min = document.getElementById("min").value;
  var pdf = new jsPDF({
    orientation: "portrait",
    unit: "mm",
    format: "letter"
  });

  //there is more non relevant code, I did not want to paste a whole file
<input type="button" value="Click me to get you a PDF file." onclick="Mathproblems()" />

1 answer

  • answered 2019-10-15 15:10 Yunhai

    you might want to get rid of your little / inside your <input> tag instead of <input/> and probably check the structure to see if all the codes are wrapped correctly. The following code is the simplified structure. I assume you are not using jquery or not other libs. Otherwise for Jquery you need to wrap your function inside

    $(function() {});
    

    <script>
    function Mathproblems() {
        var max = document.getElementById("max").value;
        var min = document.getElementById("min").value;
        console.log(max);
        console.log(min);
      }
    </script>
    <body>
    <input id="max" value="maxvalue" >
    <input id="min" value="minvalue" >
    <input type="button" value="Click me to get you a PDF file." onclick="Mathproblems()">
    </body>