views:

30

answers:

1

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
Thank you so much, that worked perfectly
Omar Abdallah