Basically, I have a form and a validation function that executes when a form is submitted. However, I want some other codes to run before the validation runs. I tried this: How to order events bound with jQuery, but it does not work.
Basically, I have a form and a validation function that executes when a form is submitted. However, I want some other codes to run before the validation runs. I tried this: How to order events bound with jQuery, but it does not work.
Share
Improve this question
edited May 23, 2017 at 11:45
CommunityBot111 silver badge
asked Nov 25, 2011 at 1:20
Leo JiangLeo Jiang26.3k5959 gold badges177177 silver badges328328 bronze badges3
Why not literally put a call to "some other codes" right before you do the validation?
– jli
CommentedNov 25, 2011 at 1:35
The first part is in an external file, the second part is generated with PHP.
– Leo Jiang
CommentedNov 25, 2011 at 2:12
You could still have a call to a function right before the validation, and then define that function somewhere else.
– jli
CommentedNov 25, 2011 at 2:13
$('form').submit(function(){
beforeSubmit(function(){
// this function is the 'callback' function
if($(this).find('error').exists(event))
event.preventDefault();
});
});
function beforeSubmit(fn) {
if($('#url').val=='http://'){
$('#url').val('');
alert('test');
}
// call the 'callback' function you gave as argument
fn();
}