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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Anchor Links in a Drop-Down Box 1

Status
Not open for further replies.

JJOHNS

MIS
Sep 12, 2001
171
US
I have a web page that is basically a list of states, with information about each state. It's a very long page, so I put links to each state title at the top of the page, using anchors. Now, to take up less space at the top of the page, I want to put the anchor references in drop-down lists.

Using this, I get a drop-down box, but the selections don't take me to that part of the page (the anchors work without the drop-down list):

<select>
<option value = "#alabama">Alabama
<option value = "#alaska">Alaska
<option value = "#arizona">Arizona
</select>

Can someone tell me the Javascript I need to add to make these links work?

Thanks.
 
Code:
<select onchange="location.replace(location.href + this.options[this.selectedIndex].value);">
<option value = "#alabama">Alabama</option>
<option value = "#alaska">Alaska</option>
<option value = "#arizona">Arizona</option>
</select>

--Chessbot

"In that blessed region of Four Dimensions, shall we linger on the threshold of the Fifth, and not enter therein? Ah, no! [...] Then, yielding to our intellectual onset, the gates of the Sixth Dimension shall fly open; after that a Seventh, and then an Eighth -- --" Flatland, A. Square (E. A. Abbott)
 
Works great. Thanks a lot. I'm away from home this week and I left my books behind...
 
Just a note, not sure which method you prefer:

[tt]location.replace()[/tt] actually replaces the current page's location in the browser history, so if the user presses back, the current page is lost.

In some situations, this is very helpful. If, however, you want to retain full history, you can use [tt]window.location = 'url'[/tt] instead.

*cLFlaVA
----------------------------
[tt]Sigs cause cancer.[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top