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.
Here's what I have:
$('form').submit(function(){
$('form').trigger('before-submit');
if($(this).find('error').exists(event))
event.preventDefault();
});
$('form').bind('before-submit', function(e) {
if($('#url').val=='http://')
$('#url').val('');
alert('test');
});
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.
Here's what I have:
$('form').submit(function(){
$('form').trigger('before-submit');
if($(this).find('error').exists(event))
event.preventDefault();
});
$('form').bind('before-submit', function(e) {
if($('#url').val=='http://')
$('#url').val('');
alert('test');
});
You could do:
$(function() { $('#formLogin').submit( function() { alert("Something"); //do something else here return true; }); });
how about this:
$('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();
}