title: Uncaught ReferenceError: submitToAPI is not defined at HTMLButtonElement.onclick
body: <p>I am creating a form filling website it should return alert message if contact,email is not up to our standard. </p>
  
  <p>But I am getting this error Uncaught ReferenceError: submitToAPI is not defined at HTMLButtonElement.onclick </p>
  
  <p>var URL is I am passing these data to AWS API gateway and trigger a lambda function. </p>
  
  <p>form html code</p>
  
  <pre><code>&lt;h4&gt;Name:&lt;/h4&gt;
  &lt;input type="text" style="height:35px;" id="name-input" placeholder="Enter name here…" class="form-control" style="width:100%;" /&gt;&lt;br/&gt;
  &lt;h4&gt;Company Name:&lt;/h4&gt;
  &lt;input type="text" style="height:35px;" id="cname-input" placeholder="Enter name here…" class="form-control" style="width:100%;" /&gt;&lt;br/&gt;
  &lt;h4&gt;Contact Number:&lt;/h4&gt;
  &lt;input type="phone" style="height:35px;" id="phone-input" placeholder="Enter phone number" class="form-control" style="width:100%;"/&gt;&lt;br/&gt;
  &lt;h4&gt;Email:&lt;/h4&gt;
  &lt;input type="email" style="height:35px;" id="email-input" placeholder="Enter email here…" class="form-control" style="width:100%;"/&gt;&lt;br/&gt;4&gt;
  &lt;div class="g-recaptcha" data-sitekey="6Lc7cVMUAAAAAM1yxf64wrmO8gvi8A1oQ_ead1ys" class="form-control" style="width:100%;"&gt;&lt;/div&gt;
  &lt;button type="button" onClick="submitToAPI(event)" class="btn btn-lg" style="margin-top:20px;"&gt;Submit&lt;/button&gt;
  </code></pre>
  
  <p>javascript    </p>
  
  <pre><code>&lt;script language="JavaScript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js" &gt;
  function submitToAPI(e) {
         e.preventDefault(e);
         var URL = "https://abc1234.execute-api.us-east-1.amazonaws.com/01/contact";
  
              var e_name = /[A-Za-z]{1}[A-Za-z]/;
              if (!e_name.test($("#name-input").val())) {
                           alert ("Name can not less than 2 char");
                  return;
              }
          var e_cname = /[A-Za-z]{1}[A-Za-z]/;
              if (!e_cname.test($("#cname-input").val())) {
                           alert ("Name can not less than 2 char");
                  return;
              }
              var e_phone = /[0-9]{10}/;
              if (!e_phone.test($("#phone-input").val())) {
                  alert ("Please enter valid mobile number");
                  return;
              }
              if ($("#email-input").val()=="") {
                  alert ("Please enter your email id");
                  return;
              }
  
              var e_email = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,6})?$/;
              if (!e_email.test($("#email-input").val())) {
                  alert ("Please enter valid email address");
                  return;
              }
  
         var e_name = $("#name-input").val();
         var e_cname = $("#cname-input").val();
         var e_phone = $("#phone-input").val();
         var e_email = $("#email-input").val();
  
         var data = {
            name : e_name,
        cname : e_cname,
            phone : e_phone,
            email : e_email,
  
          };
  
         $.ajax({
           type: "POST",
           url : "https://abc1234.execute-api.us-east-1.amazonaws.com/01/contact",
           dataType: "json",
           crossDomain: "true",
           contentType: "application/json; charset=utf-8",
           data: JSON.stringify(data),
  
  
           success: function () {
             // clear form and show a success message
             alert("Successfull");
             document.getElementById("contact-form").reset();
         location.reload();
           },
           error: function () {
             // show an error message
             alert("There is some issue with our servers please contact our landline for enquiry");
           }});
       }
  &lt;/script&gt;
  </code></pre>