# Email/Database & Dropdown Issue

**URL:** <https://forum.wixstudio.com/t/email-database-dropdown-issue/21031>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [September 4, 2019, 2:14pm UTC](https://forum.wixstudio.com/t/email-database-dropdown-issue/21031 "2019-09-04T14:14:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jfriede](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jfriede/32/9362_2.png) [@jfriede](https://forum.wixstudio.com/u/jfriede)\
**Post date:** [September 4, 2019, 2:14pm UTC](https://forum.wixstudio.com/t/email-database-dropdown-issue/21031/1 "2019-09-04T14:14:16Z")

</div>

Here’s my website for reference.  
[https://www.deafhoosiers.com/search-directory](https://www.deafhoosiers.com/search-directory)

**1.** I have mailto: set up in the URL in the database. The email icon is connected to the database and is onClick. I tried to test the icon and nothing is happening. I was expecting a pop up of an email app of any kind to show up. Is there a code I need for that part or am I missing something?

**2.** The dropdown is showing multiples when I only want one value for each category. I tried several tutorials and am still seeing multiples.

Here’s the code for the page: (please note: there’s a search bar code included and they work)

```javascript
import {local} from 'wix-storage';
 
import wixData from 'wix-data';
 
 
export function searchButton_click() {
    search();
}
 
export function searchBar_keyPress(event, $w) {
 if (event.code === 13){
         search();
    }
}
 
function search() {
    wixData.query('staffdirectory')
   .contains('lastName', $w("#searchBar").value)
   .or(wixData.query('staffdirectory').contains('lastName', $w("#searchBar").value))
  .or(wixData.query('staffdirectory').contains('firstName', $w("#searchBar").value))
  .or(wixData.query('staffdirectory').contains('department', $w("#searchBar").value))
      .find()
       .then(res => {
        $w('#results').data = res.items;
    });
 
}

$w.onReady(function () {
 
 

    wixData.query("staffdirectory")

      .limit(1000)

      .find()

      .then(results => {

 const uniqueItems = getUniqueItems(results.items);

           $w("#llisting").options = buildOptions(uniqueItems);

      });

 

 function getUniqueItems(items) {

 const itemsOnly = items.map(item => item.title);

 return [...new Set(itemsOnly)];

    }

 

 function buildOptions(uniqueList) {

 return uniqueList.map(curr => {

 return {label:curr, value:curr};

        });

    }

});

 

export function llisting_change(event, $w) {

 let sort = $w("#llisting").value;

    $w("#staffdirectory").setFilter(wixData.filter().eq("department", sort));

}

```

---

<div class="post-metadata">

**Author:** ![viktoriian](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/viktoriian/32/14423_2.png) [@viktoriian](https://forum.wixstudio.com/u/viktoriian)\
**Post date:** [September 5, 2019, 11:08am UTC](https://forum.wixstudio.com/t/email-database-dropdown-issue/21031/2 "2019-09-05T11:08:53Z")

</div>

Hi!

1. If you’re just using a regular email Icon from Buttons section of the Wix Editor and only need one email to send mails to (f.ex. “Contact us” feature), you can check out how to connect it here: [https://support.wix.com/en/article/creating-a-clickable-email-address](https://support.wix.com/en/article/creating-a-clickable-email-address)  
(the section “To link a button to an email address” on the bottom)

If you need to take an email from the database and send an email to the different users each time (f.ex: “Sign me up for newsletter” feature), you’ll need to write some code. I would suggest using wixCrm for that ( [https://www.wix.com/corvid/reference/wix-crm.html](https://www.wix.com/corvid/reference/wix-crm.html) )

---

<div class="post-metadata">

**Author:** ![viktoriian](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/viktoriian/32/14423_2.png) [@viktoriian](https://forum.wixstudio.com/u/viktoriian)\
**Post date:** [September 5, 2019, 11:18am UTC](https://forum.wixstudio.com/t/email-database-dropdown-issue/21031/3 "2019-09-05T11:18:53Z")

</div>

1. About the second one: in your getUniqueItems() function, after you map the array and assign it to itemsOnly array, use a for loop / Lodash .uniq function / any other library’s function / your own custom solution to filter out duplicate values

---

<div class="post-metadata">

**Author:** ![jfriede](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jfriede/32/9362_2.png) [@jfriede](https://forum.wixstudio.com/u/jfriede)\
**Post date:** [September 10, 2019, 6:17pm UTC](https://forum.wixstudio.com/t/email-database-dropdown-issue/21031/4 "2019-09-10T18:17:43Z")

</div>

Thanks. I’ve looked through them. Triggered emails will not work in my case. I have a staff directory with an icon linking to the database. The field is set at url with mailto:

![](https://us1.discourse-cdn.com/wix/original/3X/a/f/af8d0329edcceb90464d5fe01ce9069e00346846.png)

```javascript
function email_click() {
    wixData.query('staffdirectory')
    .find('email')
    .then(res=> {
    $w("#email").link = res.items;
});
}

```

It should be very simple. I do show the mailto: when I hover but when clicking, it doesn’t do anything. ([Indiana School For The Deaf - Indiana School For The Deaf](http://www.deafhoosiers.com/search-directory)) but it’s not doing anything when I click on the button. It should automatically open up our email app to send the email.

---

<div class="post-metadata">

**Author:** ![benibrodi](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/benibrodi/32/9244_2.png) [@benibrodi](https://forum.wixstudio.com/u/benibrodi)\
**Post date:** [September 10, 2019, 8:36pm UTC](https://forum.wixstudio.com/t/email-database-dropdown-issue/21031/5 "2019-09-10T20:36:15Z")

</div>

@jfriede

I dont think that just work like this: You should use _wixloaction.to(…)_  
[https://www.wix.com/corvid/reference/wix-location.html#to](https://www.wix.com/corvid/reference/wix-location.html#to)

And you code should look somethink like that:

```javascript
import wixLocation from 'wix-location';

...

function email_click() {
    wixData.query('staffdirectory')
    .find('email')
    .then(res=> {
        const eMail= res.items;

        $w("#email").onClick( eMail => {
             const subject = "EMAIL TITLE TEXT";  
             wixLocation.to(
                `mailto:${eMail}?subject=` +         
                encodeURIComponent(subject)    
             ); 
        })
    });
}

```

---

<div class="post-metadata">

**Author:** ![jfriede](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jfriede/32/9362_2.png) [@jfriede](https://forum.wixstudio.com/u/jfriede)\
**Post date:** [September 11, 2019, 1:09pm UTC](https://forum.wixstudio.com/t/email-database-dropdown-issue/21031/6 "2019-09-11T13:09:54Z")

</div>

@benibrodi Thank you! I tried it, didn’t work and made some tweaks. Works now! YAY! Thank you!

```javascript
function email_click() {
    wixData.query('staffdirectory')
    .find('email')
    .then(res=> {
 const email= res.items;

        $w("#email").onClick(eMail => {
 const subject = "WEBMAIL";  
             wixLocation.to(`mailto:${email}?subject=` +         
                encodeURIComponent(subject)    
             ); 
        })
    });
}

```
