Disable button on form submission

前端 未结 17 1662
伪装坚强ぢ
伪装坚强ぢ 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:01

    if the validation is successful, then disable the button. if it's not, then don't.

    function validate(form) {
      // perform validation here
      if (isValid) {
        form.mySubmitButton.disabled = true;
        return true;
      } else {
        return false;
      }
    }
    
    
    ...

提交回复
热议问题