[Solved-5 Solutions] “Submit is not a function” error in JavaScript




Error Description:

    When we try to submit a form with JavaScript, we get an error ".submit is not a function" shown.

    <form action="product.php" method="get" name="frmProduct" id="frmProduct" enctype="multipart/form-data">
    
    <input onclick="submitAction()" id="submit_value" type="button" name="submit_value" value="">
    
    </form>
    
    <script type="text/javascript">
        function submitAction()
        {
            document.frmProduct.submit();
        }
    </script>
    
    click below button to copy the code. By - JavaScript tutorial - team

    Also this code:

    <script type="text/javascript">
        function submitAction()
        {
            document.forms["frmProduct"].submit();
        }
    </script>
    
    click below button to copy the code. By - JavaScript tutorial - team

    Shows the same error.

    Solution 1:

      submit is not a function means that you named your submit button or some other element submit. Rename the button to btnSubmit and your call will magically work.

      • When you name the button submit, you override the submit() function on the form.

      Solution 2:

        Let the button handle which form object to use:

        onclick="return SubmitForm(this.form)"
        
        click below button to copy the code. By - JavaScript tutorial - team

        and with the js:

        function SubmitForm(frm) {
            frm.submit();
        }
        
        
        click below button to copy the code. By - JavaScript tutorial - team

        Solution 3:

          • Make sure that there is no another form with the same name and make sure that there is no name="submit" or id="submit" in the form.

          Solution 4:

            If you have no opportunity to change name="submit" you can also submit form this way:

            function submitForm(form) {
                var submitFormFunction = Object.getPrototypeOf(form).submit;
                submitFormFunction.call(form);
            }
            
            click below button to copy the code. By - JavaScript tutorial - team

            Solution 5:

              Use:

              var enviar = document.getElementById("enviar");
              enviar.type = "submit"; 
              
              click below button to copy the code. By - JavaScript tutorial - team

              Related Searches to “Submit is not a function” error in JavaScript

              Adblocker detected! Please consider reading this notice.

              We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

              We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

              We need money to operate the site, and almost all of it comes from our online advertising.

              Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.

              ×