Reputation: 5356
I have a code like this for the submit button button[type='submit]
of a form:
$('#submitButtonId').click(function () {
setTimeout(function() { return false; }, 100);
});
But the submitting of the form still continues. How can I stop the submitting of the form by return false
with a time delay on the click
event of the submit button?
We need the time delay for some UI purposes. Is there a different approach to achieve this?
I am using jQuery v1.11.0 for a modern (up-to-date) browser.
Upvotes: 0
Views: 3035
Reputation: 1764
Not knowing the context of this UI change, I would suggest you use e.preventDefault() first
e.g.
$('#submitButtonId').click(function (e) {
e.preventDefault();
var $form = $(this);
setTimeout(function(){
$form.submit();
return false;
}, 100);
});
Upvotes: 4
Reputation: 727
I think you want call click function after 100 miliseconds and check click or cancel.You can try
$('#submitButtonId').click(function () {
e.preventDefault();
setTimeout(function() {clickbutton() }, 100);
});
function clickbutton()
{
// if(conditionok)submit();
}
Upvotes: 0