How to submit form only once after multiple clicking on submit?

后端 未结 9 2225
北荒
北荒 2020-12-13 10:41

I am having problem that when i am trying to submit the form by clicking on the submit button it takes some time to post request during this if i am again click on the Submi

9条回答
  •  醉话见心
    2020-12-13 11:24

    Disabling the button is one solution, but potentially poses a problem for keyboard users who just hit enter to submit a form. In this scenario, the button won't be disabled. The sure-fire method would be to handle the onsubmit event like so:

    (function () {
        var allowSubmit = true;
        frm.onsubmit = function () {
           if (allowSubmit)
               allowSubmit = false;
           else 
               return false;
        }
    })();
    

    (well, as sure-fire as you can get with JS enabled anyway). You could disabled the button as a visual confirmation to the end user that the form can only be submit once too.

提交回复
热议问题