Insert into with waiting time

Asked

Viewed 80 times

0

I have a form that his action sends to a.php file that makes an Insert in the database with the information passed by the form, and I’ve noticed that if I double click very quickly on the Ubmit button it sends two identical records to the database, someone knows how to do a waiting system for example if I send a record now at 00:41:27 I will only be able to send another at 00:41:29 a 2 second timer, or when clicking the Submit button once it blocks so it does not send twice the same record.

1 answer

4


You can disable input with javascript:

function funcao (obj) {
  obj.disabled = true; // desabilita o input
  console.log("qualquer código dentro da função.");
};
<input type="submit" value="Teste1" onclick="this.disabled=true" />
<br />
<input type="submit" value="Teste2" onclick="funcao(this)" />

To funcao is only used in the Teste2 click. Advantage that can run multiple codes in the same event, while Teste1 is limited to disabling the button.

Within the funcao you can still use this code snippet:

setTimeout(function(){
    obj.disabled = false;
}, 3000)

This will enable the button again in 3 seconds.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.