0

I am creating one form it's working fine,i having one issue when user without filled the one field means i want show the error message ,error msg also working but i want show that particular field so i am using scrollTo function but it not moving...

$(document).ready(function() {
  $("#btn-submit").click(function() {
    if ($('#FranchiseeForm').valid()) {
      //alert("Sucess");
      $.ajax({
        type: "POST",
        url: "php/register-check.php",
        data: $('form#FranchiseeForm').serialize(),
        success: function(data) {
          var result = data["response"];
          console.log(result);
          if (result == 'success') {
            $('body').animate({
              scrollTop: $('#email_success')
            }); //This one working for me
            $('#email_success').fadeOut(3000);
            $(".panel-title").hide();
            $("#email_success").show();
            $('#fname').val("");
            $('#lname').val("");
            $('#email').val("");
            $('#mobile').val("");
            $('#address').val("");
            $('#countryId').val("");
            $('#stateId').val("");
            $('#cityId').val("");
            $('#pincode').val("");
            $('#capital').val("");
            $('#timeframe').val("");
            $('#location').val("");
          } else {
            $("#email_error").show();
          }
        },
      });
      return false;
    } else {
      $('body').animate({
        scrollTo: $('#address')
      }); //this code not working for me,
    }
  });
});
Barmar
  • 596,455
  • 48
  • 393
  • 495
Raja R
  • 9
  • 2

1 Answers1

0

scrollTo is not an option in .animate() ... you can try

$('body').animate({
    scrollTop: $('#address').offset().top
});

OR you can read about scrollTo() here

Mohamed-Yousef
  • 22,772
  • 3
  • 17
  • 27
  • this code working,but i am adding one more filed like $('body').animate({ scrollTop: $('#timeframe').offset().top }); ,it will come like jig jag,1st will go to top and again it come down – Raja R Dec 30 '15 at 06:37
  • @RajaR I really can't got your point .. if you can make a demo it will be better https://jsfiddle.net/ .. or you can send website link if possible – Mohamed-Yousef Dec 30 '15 at 06:45
  • if i am not filled the address field means,your code working properly and also i am not filled the #capital field means how to write the code – Raja R Dec 30 '15 at 06:55
  • @RajaR in this case you can check if($('#Capital').val().trim() == ''){// there is no Capital value // make action } – Mohamed-Yousef Dec 30 '15 at 07:01