# Update Text field Based on Dropdown

**URL:** <https://forum.wixstudio.com/t/update-text-field-based-on-dropdown/12554>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [February 3, 2019, 2:27am UTC](https://forum.wixstudio.com/t/update-text-field-based-on-dropdown/12554 "2019-02-03T02:27:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![alleny87](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@alleny87](https://forum.wixstudio.com/u/alleny87)\
**Post date:** [February 3, 2019, 2:27am UTC](https://forum.wixstudio.com/t/update-text-field-based-on-dropdown/12554/1 "2019-02-03T02:27:48Z")

</div>

Hi All,  
I’m a bit new to using wix code but I offered a friend to help solve this problem.  
We have a dropdown that is connected a dataset for it options, what we would like is when the user selects from the dropdown the trip they would like it updates the text box below it to the matching “tripPrice” column that corresponds with the selection from the dropdown.

We have been googling all over searching and implemetning various methods but cant get it to update properly.  
Here is the page/form:

![](https://us1.discourse-cdn.com/wix/original/3X/e/8/e835f5ac7b3b6d2b7a2d6eca2ff77b9086da8094.png)  
And the database:

 ![](https://us1.discourse-cdn.com/wix/original/3X/0/8/083f59274367f4dfc327b59b90e3a05f894e5727.png)  
The dropdown is mapped to the Headline Column (fieldkey = title)  
and the text box should return the “Trip Price” (fieldkey = tripPrice) column when they pick the associated trip.

I have tried:

> **[Velo by Wix: Full-Stack Web Dev | Build Professional Web Apps](https://community.wix.com/velo/forum/coding-with-velo/setting-element-text-from-database-query)**
>
> Velo brings together the tools you need to create professional web apps, faster. Develop smarter with the visual UI Editor, IDE, JavaScript, Velo APIs and more.

> **[Velo by Wix: Full-Stack Web Dev | Build Professional Web Apps](https://community.wix.com/velo/forum/coding-with-velo/update-text-field-when-a-dropdown-is-selected)**
>
> Velo brings together the tools you need to create professional web apps, faster. Develop smarter with the visual UI Editor, IDE, JavaScript, Velo APIs and more.

A few others and a few homegrown ideas with no luck… any help would really be appreciated. I know were missing something, probably simple, here.  
Thanks

---

<div class="post-metadata">

**Author:** ![mhammouz](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mhammouz/32/4033_2.png) [@mhammouz](https://forum.wixstudio.com/u/mhammouz)\
**Post date:** [February 3, 2019, 8:16am UTC](https://forum.wixstudio.com/t/update-text-field-based-on-dropdown/12554/2 "2019-02-03T08:16:29Z")

</div>

Hi,

What you can do is to query your dataset based on the value selected from the dropdown, then get its tripPrice to be displayed. To achieve that, you should use [wix-data #Query](https://www.wix.com/code/reference/wix-data.html#query) . EX:

```javascript
wixData.query("myCollection")
  .eq("title", $w("#dropdown").value)
  .find()
  .then( (results) => {
    if(results.items.length > 0) {
      let firstItem = results.items[0]; //see item below
    } else {
      // handle case where no matching items found
    }
  } )
  .catch( (err) => {
    let errorMsg = err;
  } );
   

```

```javascript
/* firstItem is:
 *
 * {
 * "_id": "00002",
 * "_owner": "ffdkj9c2-df8g-f9ke-lk98-4kjhfr89keedb",
 * "_createdDate": "2017-05-24T12:33:18.938Z",
 * "_updatedDate": "2017-05-24T12:33:18.938Z",
 * "title": "TEST TRIP 2",
 * "tripPrice": "169.68"
 * }

```

* * *

P.s: Place the query inside an onChange function for the dropdown

Hope this helps!  
Best,

Mustafa

---

<div class="post-metadata">

**Author:** ![alleny87](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@alleny87](https://forum.wixstudio.com/u/alleny87)\
**Post date:** [February 3, 2019, 10:47am UTC](https://forum.wixstudio.com/t/update-text-field-based-on-dropdown/12554/3 "2019-02-03T10:47:01Z")

</div>

Hi Mustafa,

Thanks for the recommendation, iv been trying to make a query work but its not quite working, here is what i have:

```javascript
export function tripSelection_change(event,$w) {
  wixData.query("tripDatesDataset")
  .eq("title", $w('#tripSelection'))
  .find()
  .then( (results) => {
 if(results.item.length > 0) {
 let firstItem = results.items[0];
      $w('#tripTotal').text = firstItem.tripPrice;
      console.log(results.items);
    } else {
      $w('#tripTotal').text = "0.00";
    }    
    })
  .catch( (err) => {
 let errorMsg = err;
  });
}

```

No errors, but the value is not updated and there is nothing sent to the console

---

<div class="post-metadata">

**Author:** ![joannacastro96](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/joannacastro96/32/14694_2.png) [@joannacastro96](https://forum.wixstudio.com/u/joannacastro96)\
**Post date:** [September 21, 2019, 3:32pm UTC](https://forum.wixstudio.com/t/update-text-field-based-on-dropdown/12554/4 "2019-09-21T15:32:09Z")

</div>

Hi Mustafa!

I have the exact same problem (in my case trying to display delivery costs per country) and still haven´t been able to find a solution… Do you happen to have any updates?  
Thanks a lot,

Joanna

---

<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 21, 2019, 3:45pm UTC](https://forum.wixstudio.com/t/update-text-field-based-on-dropdown/12554/5 "2019-09-21T15:45:49Z")

</div>

Check the connection! Have the “Button” the property “onChange” ? Check the IDs ! Is it the same like in your code? Make a “Console.log(“Button clicked”);” first before every query to be sure that it works.  
And when you have the Message in the console “Button clicked” then it’s time to go to the next chapter.

---

<div class="post-metadata">

**Author:** ![nhacua00nguoiviet](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/nhacua00nguoiviet/32/11634_2.png) [@nhacua00nguoiviet](https://forum.wixstudio.com/u/nhacua00nguoiviet)\
**Post date:** [January 2, 2020, 10:57am UTC](https://forum.wixstudio.com/t/update-text-field-based-on-dropdown/12554/6 "2020-01-02T10:57:15Z")

</div>

export function tripSelection\_change(event,$w) {  
wixData.query(“tripDatesDataset”)  
.eq(“title”, $w(‘#tripSelection’).value)  
.find()  
.then( (results) =\> {  
**if** (results.item.length \> 0) {  
**let** firstItem = results.items[0];  
$w(‘#tripTotal’).text = firstItem.tripPrice;  
console.log(results.items);  
} **else** {  
$w(‘#tripTotal’).text = “0.00”;  
}  
})  
. **catch** ( (err) =\> {  
**let** errorMsg = err;  
});  
}

lets check carefully your code…you missed alot

---

<div class="post-metadata">

**Author:** ![imzainulabideen12](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/imzainulabideen12/32/16570_2.png) [@imzainulabideen12](https://forum.wixstudio.com/u/imzainulabideen12)\
**Post date:** [January 2, 2020, 1:26pm UTC](https://forum.wixstudio.com/t/update-text-field-based-on-dropdown/12554/7 "2020-01-02T13:26:56Z")

</div>

Great [,](https://instaplusapk.com/) Help
