Search code examples
javascriptc#htmlasp.netrazor

How to disable two submit buttons when one of them is clicked


I have two submit buttons in a cshtml file.

<button type="submit" name="SubmitButton" value="accept" id="buttonAccept">Accept</button>

<button type="submit" name="SubmitButton" value="refuse" id="buttonRefuse"Refuse</button>

I am trying to disable these two buttons when either one of them is clicked. Is there a way to do so?


Solution

  • You can use the similar code for both buttons. onClick on one button disable the other button and so.

    <button type="submit" name="SubmitButton" value="accept" id="buttonAccept" onclick="return foo();">Accept</button>
    
    function foo() {
       document.getElementById("buttonAccept").disabled = true;
       document.getElementById("buttonRefuse").disabled = true;
       return true;
    }