Multiple submit Button click problem?

前端 未结 3 408
予麋鹿
予麋鹿 2020-12-22 01:56

I have a form which inserts data in DB on Submit button click but the problem is when client click the button multiple times its sends multiple create requests means multipl

3条回答
  •  -上瘾入骨i
    2020-12-22 02:45

    Do not disable the button, just prevent the second submit.

    this little script does the job but it assumes there is a postback at a certain moment.

    var formhandler = function() {
       var submit, isSubmit = false;
       submit = function(){
                    // flop and return false once by the use of operator order.
        return isSubmit != (isSubmit = true);
        };
        return {
           submit: submit
        };
    }(); // <-- use direct invcation to keep the internal variables "static"
    

    attach it by :

       document.forms[0].onsubmit = formhandler.submit;    
    

    or

       OnClientClick = "formhandler.submit()";
    

提交回复
热议问题