Software, your way.
burger menu icon
WillMaster

WillMaster > LibraryWeb Page and Site Features

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Dropdown Links

A dropdown is a special form field created with the select tag. When the dropdown is tapped, it reveals a list of options to select from. An example dropdown is further below.

A dropdown selection can act like a link, which is what this article is about. In the source code further below, you'll see that each option has a URL for a value.

When an option is selected, the browser is sent to the option's URL value. The URL would be to another web page or to a different section of the current web page.

To implement, give the select field this onchange attribute.

onchange="if(this.options[this.selectedIndex].value){location.href=this.options[this.selectedIndex].value}"

The this.options[this.selectedIndex].value part (in both places) is code to determine the URL that the browser is being sent to. The URL is determined by the value of the option the person selected.

The location.href part is what sends the browser to the new URL.

I'll provide an example and its source code. Then talk a bit about it.

Here is the source code for the example.

<select onchange="if(this.options[this.selectedIndex].value){location.href=this.options[this.selectedIndex].value}">
<option value="">- Select a location -</option>
<option value="#testing">The element with id="testing"</option>
<option value="https://spamfreeform.com">The spamfreeform.com website</option>
<option value="/">This site's home index page</option>
</select>

As mentioned earlier, the select field has an onchange attribute. The attribute sends the browser to the link provided by the selected option.

Each option has a value that is the link (except the first one, with an empty value). It also has dropdown text, which the example uses to indicate what type of link the value contains.

The #testing fragment link scrolls the browser window to the div or other HTML tag that has an id="testing" attribute. (The first paragraph in this article has the <p id="testing"> HTML tag.)

The https://spamfreeform.com absolute link takes the browser to the indicated website.

And the / relative link takes the browser to the index page of the current domain.

I used to see many dropdown links during the earlier part of my internet experience. Their popularity seems to have dwindled. Now, you can be one of the site owners who reintroduce dropdown links to the later generation of interneters.

(This content first appeared in Possibilities newsletter.)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2025 Will Bontrager Software LLC