Disable button after click

2

I have a form that sends tans to my database when I click the button.

            

What can I do to disable the button after clicking? I do not want the button to be triggered more than once.

    
asked by anonymous 19.09.2017 / 21:07

3 answers

3

Using pure JavaScript, you can do it using:

<button onclick="this.disabled = true;">Curtir</button>
    
19.09.2017 / 21:18
0

Assuming you use Jquery:

<button onclick="dasabilitaBotao(this)">Curtir</button>
<script> 
    function desabilitaBotao(element){
    $(element).prop('disabled', true)
    }
</script>
    
19.09.2017 / 21:14
0

There are several ways to do this, but you will basically need to capture the click event and use the disabled property.

link

function desabilitaBotao(){
     document.getElementById("BtnCurtir").disabled = true;
}

$("#BtnCurtir2").on("click", function(){
  $(this).prop("disabled", true);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><!--Existemdiversasformasdevocêfazerisso--><buttononclick="this.disabled = true;">Curtir</button>
<button onclick="desabilitaBotao()" id="BtnCurtir">Curtir</button>
<button id="BtnCurtir2">Curtir</button>
    
19.09.2017 / 21:42