“Submit is not a function” error in JavaScript

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

提交回复
热议问题