Software, your way.
burger menu icon
WillMaster

WillMaster > LibraryManaging Website Forms

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 to Hide Email Addresses

When you publish email address links on web pages (<a href="mailto:…">), the addresses are likely to be harvested by spambots.

Once in a spammer's database, there it is, for as long as the database exists. You can expect spam forever.

The technique described in this article is to hide email addresses at websites that have multiple email destinations, all at the same domain. The destinations are selected by the site visitor.

Example:

I want to send an email to:

If you have only one email address to send email to, the dropdown can still be used. There would be only one destination to select. You may also read other articles published at Willmaster.com about how to obfuscate email addresses. There is a search box near the top-right of this page.

If your destinations include two or more domains, the JavaScript (further below) will need to be modified. The modification is outside the scope of this article, but it certainly can be done. Use the Willmaster.com contact form and ask me about it.

To implement the dropdown to hide email addresses, three sets of code need to be on your page.

  • The dropdown list.
  • An empty link.
  • JavaScript.

Customizations include the dropdown list to suit your implementation. And the domain name the email is to be sent to.

Here is the code for all three sections. (They may all be together in your web page source code.) Notes follow.

<select onchange="handleSending(this.options[this.selectedIndex].value)">
<option value="">Select the destination</option>
<option value="bill">The billing department</option>
<option value="george">Sales</option>
<option value="sue">Report site glitch</option>
</select>

<a id="addyLink" href=".."></a>

<script type="text/javascript">
function handleSending(s)
{
   var websiteDomain = "example.com";
   var d = document.getElementById("addyLink");
   d.href = "am".split("").reverse().join("") + 
            "i" + 
            ":otl".split("").reverse().join("") + 
            s + 
            String.fromCharCode(64) + 
            websiteDomain;
   d.click();
}
</script>

Notes —

The dropdown —

When you create the dropdown for your website, the option values are the "name" part of an email address, the part before the "@" character: name@example.com

Leave the select tag as is in the above source code unless you want to change the name of the JavaScript function that handles a dropdown selection. Currently, it is handleSending and would need to be changed at both the select tag and the name of the function in the JavaScript.

The empty link —

You'll see the empty link below the dropdown and above the JavaScript in the above source code. (It is empty because no text or image is linked to.) The JavaScript will update the href value and click the link when a dropdown selection is made.

The empty link contains an id tag that you may change, if you wish. Currently, it is addyLink and would need to be changed at both the empty link and within the JavaScript function.

The JavaScript —

In the JavaScript, the example.com domain name needs to be updated to the domain name for the email addresses, the part following the "@" character: name@example.com

The function name handleSending and empty link id addyLink stay as they are unless corresponding changes are done in the select code or the empty link, respectively.

When the code is integrated into your web page source code, and tested to work correctly, the dropdown to hide email addresses system will be ready to go.

People select who to send an email to. The JavaScript updates the link with the correct mailto: protocol and email address. Then, the JavaScript clicks the link to launch the site visitor's emailing software.

The select dropdown list may be updated as necessary — without updating the rest of the system.

(This article first appeared with an issue of the 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-2024 Will Bontrager Software LLC