Automatically scroll down after submit action
Asked Answered
T

3

6

How to make my website automatically scroll down after sending e-mail from "Contact Form" which is located on the bottom of my webpage? Information about successful sending or error ouccurs below the form and after clicking that 'submit' button page is refreshing and user can see only top of the site, not the bottom...

Tswana answered 25/2, 2014 at 21:59 Comment(0)
G
13
<form id="form" action="{your_action}#form">
....
</form>

or if you want scroll to alert position :

<div id="form">
  <div class="alert">Alert</div>
  <form action="{your_action}#form">
  ...
  </form>
</div>
Glyco answered 25/2, 2014 at 22:5 Comment(0)
B
1

Post to an anchor tag on the page the sumbit is being sent to

 http://foo.com#youranchor
Bacchius answered 25/2, 2014 at 22:4 Comment(0)
B
1

The action within this opening form tag works for my site:

<form action="<?php $location = $_SERVER['PATH_INFO']; 
echo ''.$location.'#form';?>" method="post">

Essentially, you're acquiring the current URL and assigning it to $location, then echoing that out with #form tagged on the end. So the browser would read this action as:

action="currentURL.php#form"

I did it this way because my form is an include found on every page of my website, so the action needed to identify its current location before scrolling down to the form.

Bookbindery answered 28/10, 2014 at 9:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.