Re: Moving to an anchor in PHP script

From: Date: Thu, 24 Aug 2000 05:51:51 +0000
Subject: Re: Moving to an anchor in PHP script
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-13306@lists.php.net to get a copy of this message
> I have a script which generate a dynamic page. Among other things, I > have several anchors (such as <A name="intro></A>) in front of different > topics. Using a form with the post method I have a topic selector which > I want to use so it will branch to the selected topics. > > A typical <option> within this form would look like: > > <option value="#intro">1. It's time for e-commerce</option> > > Can this be done within the script? How can I control the positioning of > the page at the selected anchor? According to < http://zend.php.net/FAQ.php#7.14 >, in a <select> tag with single selection, the name of the <select> tag is given the value of the selected option. So if you have: <SELECT NAME="options" SINGLE> <!-- I think this is how you specify a single selection. --> <OPTION value="#intro">It's time for e-commerce.</OPTION> <OPTION value="#conclusion">Time for e-commerce is over.</OPTION> </SELECT> and I choose the first option, and then you do the following in the PHP form-handler: echo $HTTP_POST_VARS[options]; you'll get "#intro" printed out. So, my best idea of how to redirect the user to the appropriate page would be to do the following in your PHP form-handler (untested): header("Location: http://www.yoursite.com/page.html" . $HTTP_POST_VARS[options]); But for this you'd probably have two different pages -- one to handle the form POST action, and one that you want to send the user to. Or... You could use Javascript (untested): <SCRIPT LANGUAGE="JavaScript"> function sendUser() { document.location = "http://www.yoursite.com/page.html" + document.forms[myForm].elements[options].selectedIndex; } <FORM ONSUBMIT="sendUser()" NAME="myForm"> ... <!-- options here --> </FORM> My JavaScript's rusty as hell, and you may want to consult the DOM that's really implemented in each browser to keep it cross-browser. Of course, my first thought, the server-side implementation with a form-handler would rid you of having to rely on a browser to do the right thing. Hope this helps. :-) Dean.

« previous php.general (#13306) next »