Brett
Brett

Reputation: 20049

Submitting a form with an action that includes a hash

I have what you would call 2 "sections" on a page and the user can submit a form on the 2nd section, however if they get an error the page will reload and take them to the top of the page again...... this is annoying behavior and I want them to be taken back down to the correct spot on the page to see the error etc..

I figured I could just give the element an id such as:

<section id="my_section"></section>

...and then in the action method of the form I could input the anchor such as:

<form action="page.php#my_section" method="post">..........</form>

This works in all the browsers I tried it in, but I was wondering if this type of method has been known to cause any issues in any browsers including ones in mobiles/tablets or with certain method types such as GET?

Upvotes: 1

Views: 2134

Answers (1)

Ian Hazzard
Ian Hazzard

Reputation: 7771

In all modern browsers, the method you are using is perfectly fine. That's what hashtags are made for. However, it might be better if you try to keep the form from submitting when there's an error (using return false in JS). I'm not sure if that's possible in your case, but if you can, it will keep users from having to re-input values into the form.

Hope this helps!

Upvotes: 1

Related Questions