Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drop-Down Links to Named Anchors

Status
Not open for further replies.

DonCorr

Technical User
May 7, 2003
4
US
I want to create a drop-down list which navigates to various locations within the same HTML page. I can make a drop-down list navigate to <other> pages, and I can make the idea work with a bunch of HTML anchors, but how can this be done using a drop-down list? Is javascript absolutely required, or is there a way through plain old HTML?
 
>> Is javascript absolutely required

Yes, i think so. You have to handle the onchange event.

Code:
<select onchange=&quot;document.location = this.options(this.selectedItem).value;&quot; ... >
<option value=&quot;#thisPlace&quot;>This Place</option>
<option value=&quot;#thatPlace&quot;>That Place</option>

-pete
I just can't seem to get back my IntelliSense
 
palbano

Thanks for your quick response. I tried the code you suggested, but had no luck. Here is the code I tried:

<HTML>
<HEAD>
</HEAD>
<BODY

<FORM>
<select onChange=&quot;document.location = this.options(this.selectedItem).value;&quot;>
<OPTION VALUE=&quot;#thisPlace&quot;>This Place</OPTION>
<OPTION VALUE=&quot;#thatPlace&quot;>That Place</OPTION>
</SELECT>
</FORM>

<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>
<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
<A Name=&quot;thisPlace&quot;>THIS PLACE
<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR.
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
<A name=&quot;thatPlace&quot;>THAT PLACE<BR>

</BODY
</HTML>

Upon either selection (provided it is different from the previously-selected option) I wind up at the first anchor. I tried a few variations of the code as you entered it, including the &quot; ...&quot; at the and of the select tag. I've not come across that one before and would appreciate an explanation of what it does.

Any more ideas on the original problem? Where did I go wrong?

DonCorr
 
DonCorr, see if this helps:

<FORM name=&quot;MyForm&quot;>
<select name=&quot;mySelect&quot; onChange=&quot;document.location = this.options[this.options.selectedIndex].value&quot;>
<option>Choose One Please</option>
<OPTION VALUE=&quot;#thisPlace&quot;>This Place</OPTION>
<OPTION VALUE=&quot;#thatPlace&quot;>That Place</OPTION>
</SELECT>
</FORM>

<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>
<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>
<A Name=&quot;thisPlace&quot;>THIS PLACE<br>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
<BR><BR><BR><BR><BR><BR>
<BR><BR><BR><BR><BR><BR>
<A name=&quot;thatPlace&quot;>THAT PLACE<BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
Bla Bla Bla<BR><BR>
</BODY
</HTML>


Forget the Nobel Peace prize, I just want to take over the world!! [hammer]
 
Thanks, GUJUmOdeL. That was exactly what I needed. It seems my problem was using the ( ) in place of the [ ]. It's always something simple, once you know what it is.

There is a javacript error when &quot;Choose One Please&quot; is selected after selecting another option. I don't need the prompt, however, and the code will work just fine. Thanks again.

DonCorr


 
You're welcome man...

Forget the Nobel Peace prize, I just want to take over the world!! [hammer]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top