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.

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,


Edited by klemme

5 Years
Discussion Span
Last Post by Caio_1

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.

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!


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.