Disable button on form submission

前端 未结 17 1721
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 00:13

I have a button that I would like to disable when the form submits to prevent the user submitting multiple times.

I have tried naively disabling the button with java

17条回答
  •  广开言路
    2020-12-01 01:06

    The following function is useful without needing the disabling part which tends to be unreliable. Just use "return check_submit();" as part of the onclick handler of the submit buttons.

    There should also be a hidden field to hold the form_submitted initial value of 0;

    
    
    function check_submit (){
                if (document.Form1.form_submitted.value == 1){
                    alert("Don't submit twice. Please wait.");
                    return false;
                }
                else{
                    document.Form1.form_submitted.value = 1;
                    return true;
                }
                return false;
        }
    

提交回复
热议问题