How to go a specific portion of page after clicking Submit button?

Hi all

It is easy to go a specific portion after clicking a link, like this
to go here, <a name=“go” id=“go”></a>, we can make a link <a href=“index.html#go”>
Can you tell me how can I go to a specific portion of a page after submitting button? Normally, it displays upper portion of the page. I would appreciate your help

Thank you

There are a couple of different ways.

You can have PHP redirect to the same page, but with the fragment identifier attached.
This causes a second load to happen to the page, which you may not desire.

A second way is to have javascript perform the redirect, but keep in mind that not everyone will have javascript enabled.

thank you pmw57. i’m interested in the first solution. can you tell me how to pass fragment identifier in the same page when submitting the button?

When you consider the conditions to be right, you can update the header before any other output occurs on the page.


header('Location: ' + $_SERVER['PHP_SELF'] + '#fragmentId');

I think it is helpful. thank you pmw57 for the solution.

I’d suggest
header(‘Location: http://’.$_SERVER[‘HTTP_HOST’] . $_SERVER[‘PHP_SELF’] . ‘#fragmentId’);