“Submit is not a function” error in JavaScript

后端 未结 15 2886
遇见更好的自我
遇见更好的自我 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:32

    What I used is

    var enviar = document.getElementById("enviar");
    enviar.type = "submit"; 
    

    Just because everything else didn´t work.

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

    Solution for me was to set the "form" attribute of button

    <form id="form_id_name"><button name="btnSubmit" form="form_id_name" /></form>
    

    or is js:

    YOURFORMOBJ.getElementsByTagName("button")[0].setAttribute("form", "form_id_name");
    YOURFORMOBJ.submit();
    
    0 讨论(0)
  • 2020-11-22 00:32

    Possible solutions -
    1.Make sure that you don't have any other element with name/id as submit.
    2.Try to call the function as onClick = "return submitAction();"
    3.document.getElementById("form-name").submit();

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

    I had same issue and resolved my issue just remove name="submit" from submit button.

    <button name='submit' value='Submit Payment' ></button>
    

    Change To

    <button value='Submit Payment' ></button>
    

    remove name attribute hope it will work

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

    This topic has a lot of answers already, but the one that worked best (and simplest - one line!) for me was a modification of the comment made by Neil E. Pearson from Apr 21 2013:

    If you're stuck with your submit button being #submit, you can get around it by stealing another form instance's submit() method.

    My modification to his method, and what worked for me:

    document.createElement('form').submit.call(document.getElementById(frmProduct));

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

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

    function submitForm(form) {
        const submitFormFunction = Object.getPrototypeOf(form).submit;
        submitFormFunction.call(form);
    }
    
    0 讨论(0)
提交回复
热议问题