Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
113
rated 0 times [  119] [ 6]  / answers: 1 / hits: 34459  / 14 Years ago, wed, april 14, 2010, 12:00:00

I keep getting duplicate entries in my database because of impatient users clicking the submit button multiple times.



I googled and googled and found a few scripts, but none of them seem to be sufficient.



How can I prevent these duplicate entries from occurring using javascript or preferably jQuery?



Thanx in advance!


More From » jquery

 Answers
13

How about disabling the button on submit? That's what I do. It works fine.



$('form').submit(function(){
$('input[type=submit]', this).attr('disabled', 'disabled');
});


Disclaimer:

This only works when javascript is enabled on the user's browser. If the data that's being submitted is critical (like a credit card purchase), then consider my solution as only the first line of defense. For many use cases though, disabling the submit button will provide enough prevention.



I would implement this javascript-only solution first. Then track how many duplicate records are still getting created. If it's zero (or low enough to not care), then you're done. If it's too high for you, then implement a back-end database check for an existing record.


[#97079] Sunday, April 11, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
darleneh

Total Points: 231
Total Questions: 110
Total Answers: 94

Location: Spain
Member since Thu, Dec 23, 2021
2 Years ago
;