I have jquery validator running and I the page is so long, so I want the page to scroll up to the top because I display errors on the very top of the page above the form, doesn anyone know where I can put the code for the animation so it fires when the form has errors ?
A:
You can use the invalidHandler
option for the exact case you want, like this:
$("form").validate({
rules: { ... rules here ... }
invalidHandler: function(form, validator) {
$('html, body').animate({scrollTop: '0px'}, 300);
}
});
Nick Craver
2010-05-21 23:14:07
Thank you so much, that worked perfectly
Omar Abdallah
2010-05-22 01:27:16