Hi All. I think what am trying to do is really basic stuff, but for the life of me I can’t work out how to do it! Appreciate any help or pointers anyone could give me.
I have a very simple database which includes names and addresses. All I want to do on my site is have a dropdown list showing all the names from the database (I’ve got that bit working!), and when a user selects a name from that list, display the corresponding address in a text field.
I have achieved this in what I think is a very over complicated way with code that searches the database using the value from the dropdown list and then displaying the result in a repeater. But this just seems over kill. I don’t want to use a repeater because there will only ever be one result to display.
Surely there must be a simple way to just read the record in and display the values in a text field?
Many, many thanks!
Thanks for taking the time to look and answer. Yes, I’ve looked at them. The first one in particular is how I got my search to work using the repeater, but as I say, this is over complicated for what I need.
Thanks again for your reply and for the pointers, but I still can’t see how to do what I want. I can get the textbox to display the same value as selected in the dropdown list, but I want to display the other fields which correspond to that field. E.g., ina collection I have the following fields:
Name email
Steve steve@gmail.om
Jack jack@gmail.com
Bob bob@gmail.com
The names appear in the dropdown list. If I select Jack, I wish to display jack@gmail.com in a text box.
I must be missing something so blindingly obvious, but missing it I am!
Well if you are just selecting a name and displaying something from their dataset record on the page, then just add another text box and link it to the email field of that dataset.
Otherwise you will have to do it in code with the checking of the dropdown value and adding something like this underneath it - $w(“#dropdownEmail”).label = “Chosen Name Email”;
https://www.wix.com/corvid/forum/community-discussion/setting-element-text-from-database-query
https://www.wix.com/corvid/forum/community-discussion/update-text-field-based-on-dropdown
@givemeawhisky Thank you, thank you, thank you!
Adding another text box and simply linking it to the email field of that dataset just didn’t work for me, although that’s exactly what I thought I needed to do (maybe something in my code was screwing that up). But I did get it to work by following the second link you sent me. Basically I needed the following code:
export function dropdown1_change(event) {
wixData.query(“People”)
.eq(“name”, $w(“#dropdown1”).value)
.find()
.then( (results) => {
if (results.items.length > 0) {
let firstItem = results.items[0];
$w(‘#text37’).text = firstItem.emailAddress;
} else {
// handle case where no matching items found
$w(‘#text39’).text = “email address missing”;
}
} )
Thanks so much for all your help!