html - "Submit is not a function" error in JavaScript

ID : 10424

viewed : 19

Tags : javascripthtmldomsubmitjavascript

Top 5 Answer for html - "Submit is not a function" error in JavaScript

vote vote

95

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.

vote vote

82

<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

vote vote

71

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); } 
vote vote

65

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.

vote vote

53

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(); } 

Top 3 video Explaining html - "Submit is not a function" error in JavaScript

Related QUESTION?