Jump to content

Create id point in url from form input


amelio

Recommended Posts

Hi, I have a page with a long list of names (c1000) each with an id.

 

On that page I would like to have a form into which i put the id number, when the form is submitted it will take me to the anchor point for that id. The question I have is, how, when i press submit and reload the page, how can I then have that form input as a anchor in the url that will then take me to the place I want to go on the list when the page loads.

 

I can do it manually no problem by adding the hash tag and id to the url myselft it takes me there but It's a pain to do this every time. I would like to use a form.

 

Is this possible? any help appreciated.

 

Thanks

 

Link to comment
Share on other sites

Building upon what requinix posted, put this at the top of the page that lists the records

 

if(isset($_POST['id']))
{
    header("Location: /path/to/thispage.php#{$_POST['id']}");
    exit;
}

 

If you load the page without the post value it will display without moving to an anchor. However, if you do post a value for the ID, then the page immediately reloads the page with the appropriate anchor tag in the URL.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.