I have a submit button in my page. Sometimes when I double click it double submits obviously, and the problem is that I'm saving the information in the database so I'll have duplicate information there, and I don't want that. I tried some jquery code like below but it didn't work for me.
Here my button tag is:
<input type="submit" id="btnSubmit" class="btn btn-large btn-success" style="padding-right:40px; padding-left:40px; text-align:center;">
Jquery:
$(document).ready(function()
{
$('#btnSubmit').dblclick(function()
{
$(this).attr('disabled',true);
return false;
});
});
How to proceed further?Preventdefault is not working
$(document).ready(function () {
alert("inside click");
$("#btnSubmit").on('dblclick', function (event) {
event.preventDefault();
});
});
Use setTimeout for a more user friendly way
$(document).ready(function () {
$("#btnSubmit").on('click', function (event) {
event.preventDefault();
var el = $(this);
el.prop('disabled', true);
setTimeout(function(){el.prop('disabled', false); }, 3000);
});
});