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.
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.
Using pure JavaScript, you can do it using:
<button onclick="this.disabled = true;">Curtir</button>
Assuming you use Jquery:
<button onclick="dasabilitaBotao(this)">Curtir</button>
<script>
function desabilitaBotao(element){
$(element).prop('disabled', true)
}
</script>
There are several ways to do this, but you will basically need to capture the click event and use the disabled property.
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>