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

Anyone out there who knows this little bit of magic? :-)

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 } ?>

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

Klemme

Works just fine, Thank you fobos!

Thx fobos

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.