0

Hi all,

I have this function, which should scroll animated to an anchor.

Does anyone know how I can activate this only after a form has been submitted?

I want to animate the scroll down to either id="error" or id="succes" - depending on the form was submitted with or withour errors.

So..
WITH errors, which I am checking in PHP, I want to scroll down to div id="error".

WITHOUT errors, I want to scroll down to div id="succes".

This is the bit of code:

function goToByScroll(id) {
$('html,body').animate({scrollTop:$("#"+id).offset().top}, 'slow');
}

How do I check if the form has been submitted, and then after the page has submitted to itself, call the function and scroll down to the approiate div?
Something like this:

  if (isset($_POST['myform'])) && !empty($errors) {
   // Then I want to use jquery to animate and scroll down to div id="error"
  }
   if (isset($_POST['myform'])) && empty($errors) {
   // Then scroll down to the div with id="succes"   
   }

Sorry for the formatting problems :-/

:-)

Hope someone can help,

Klemme

Edited by klemme

3
Contributors
5
Replies
8
Views
5 Years
Discussion Span
Last Post by Caio_1
0

Try this. In this case, you already have the errors being posted in the div, so this will scroll to the div with the errors.

<?php
if(isset($_POST["myform"]) && !empty($errors)){?>
    $('html, body').animate({scrollTop: $("#error").offset().top}, 2000);
<?php } ?>
0

Thanks! I will try to use it and give you a status back!

Klemme

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.