I am currently facing issue, the user clicks a time on the Button,then the entry get inserted two times in database.
How can I solve this
I am currently facing issue, the user clicks a time on the Button,then the entry get inserted two times in database.
How can I solve this
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vishal JoshiRank #377 · 6.7K reputationPosted Apr 4, 2024, 3:26 AM EDT
Hello
There can be several possibilities to get double entries in the database. please check the below points.
Thanks
Vishal Joshi
Ishika TiwariRank #298 · 8.4K reputationPosted Apr 2, 2024, 5:24 AM EDT
it's important to ensure that the button remains disabled only for the duration necessary to prevent double submissions
Submit // JavaScript code document.getElementById('submitButton').addEventListener('click', function(event) { var submitButton = event.target; // Disable the button to prevent double submission submitButton.disabled = true; // if you want enable again setTimeout(function() { // enable the button after a delay submitButton.disabled = false; console.log('Button enabled'); }, 2000); // 2 seconds delay });Jayraj ChhayaRank #304 · 8.2K reputationPosted Apr 2, 2024, 5:54 AM EDT
If you call your API using ajax then add the below the line.
$("button").click(function(e) { e.preventDefault(); // this line is help and call this method only one time. });