“Submit is not a function” error in JavaScript

后端 未结 15 2884
遇见更好的自我
遇见更好的自我 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:24
    <form action="product.php" method="post" name="frmProduct" id="frmProduct" enctype="multipart/form-data">
    
    <input id="submit_value" type="button" name="submit_value" value="">
    
    </form>
    
    <script type="text/javascript">
    
    document.getElementById("submit_value").onclick = submitAction;
    
    function submitAction()
    {
        document.getElementById("frmProduct").submit();
        return false;
    }
    </script>
    

    EDIT: I accidentally swapped the id's around

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

    You can try

    <form action="product.php" method="get" name="frmProduct" id="frmProduct" enctype="multipart/form-data">
    
    <input onclick="submitAction(this)" id="submit_value" type="button" name="submit_value" value="">
    
    </form>
    
    <script type="text/javascript">
    function submitAction(element)
    {
        element.form.submit();
    }
    </script>
    

    Don't you have more than one form with the same name ?

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

    I had the same issue when i was creating a MVC application using with master pages. Tried looking for element with 'submit' as names as mentioned above but it wasn't the case.

    For my case it created multiple tags on my page so there were some issues referencing the correct form.

    To work around this i'll let the button handle which form object to use:

    onclick="return SubmitForm(this.form)"
    

    and with the js:

    function SubmitForm(frm) {
        frm.submit();
    }
    
    0 讨论(0)
  • 2020-11-22 00:29

    Use getElementById:

    document.getElementById ('frmProduct').submit ()
    
    0 讨论(0)
  • 2020-11-22 00:31

    giving a form element a name of submit will simple shadow the submit property . make sure you don't have a form element with the name submit and you should be able to access the submit function just fine .

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

    You should use this code :

    $(document).on("ready", function () {
           
            document.frmProduct.submit();
        });

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