“Submit is not a function” error in JavaScript

后端 未结 15 2887
遇见更好的自我
遇见更好的自我 2020-11-22 00:10

Can anyone tell me what is going wrong with this code? I tried to submit a form with JavaScript, but an error \".submit is not a function\" shown. See below for more details

相关标签:
15条回答
  • 2020-11-22 00:45

    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.

    0 讨论(0)
  • 2020-11-22 00:48

    In fact, the solution is very easy...

    Original:

        <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>
    

    Solution:

        <form action="product.php" method="get" name="frmProduct" id="frmProduct" 
    enctype="multipart/form-data">
    </form>
    
    <!-- Place the button here -->
    <input onclick="submitAction()" id="submit_value" type="button" 
        name="submit_value" value="">
    
    <script type="text/javascript">
        function submitAction()
        {
            document.frmProduct.submit();
        }
    </script>
    
    0 讨论(0)
  • 2020-11-22 00:50

    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.

    0 讨论(0)
提交回复
热议问题