Hi
I try to create a textbox with values based on what the user chooses in a dropdown list.
I have the dropdown list connected to a data base with the title, and I try this code.
export function dropdown2_change(event) {
//Add your code for this event here:
$w.onReady( () => {
$w("#dataset6").onReady( () => {
let membership_name= $w("#dataset6").getCurrentItem().title;
let membership_bank= $w("#dataset6").getCurrentItem().bank
let membership_rate= $w("#dataset6").getCurrentItem().rente
$w("#text7").text =
"Your membership in " + membership_name + " can give u an interest on " + membership_rate +
" with " + membership_bank + ".";
} );
} );
}
The user chooses one membership in the dropdown, and then, I want to show the bank and rate, that correspond to the title row in the database.
What happens is that in the textbox, only the title changes when doing a change in the dropdown list. The bank and rate output are always from the first row in the database.
All help would be highly appreciated
@eskildthorgeirsson By the time that the user chooses a value from the dropdown, the page and dataset are already loaded. There’s no need to include the onReady functions within the dropdown code function.
Thanks for feedback.
I did edit the code
export function dropdown2_change(event) {
$w.onReady( () => {
let membership_name= $w("#dataset6").getCurrentItem().title;
let membership_bank= $w("#dataset6").getCurrentItem().bank
let membership_rate= $w("#dataset6").getCurrentItem().rente
$w("#text7").text =
"Your membership in " + membership_name + " can give u an interest on " + membership_rate +
" with " + membership_bank + ".";
} );
}
Sadly, the problem remains. Only the “title” field in the textbox correspond to changes in the dropdown list.
@eskildthorgeirsson I would remove the page onReady as well, but that is a side issue.
You need to issue a setFilter command to get the dataset on the correct record before you assign those values. I take it the dropdown is connected to dataset6, right? You would need to add a another dataset tied to the same collection for the purposes of feeding the dropdown values. Then do the filter on dataset6. Otherwise, setFilter filters the dropdown values too, which presumably you would not want.
There are other ways to do this for those who have more experience writing code.
Hi
Tried to remove the page onReady, but if I did that, the “membership_name” did not respond correct longer.
Yeah, the dropdown is connected to dataset6.
Do you want me to create a dataset identical to dataset6?
Dataset6 looks like this:
The dropdown is connected like this
Connect Dropdown
Pick a connector: Dataset6
Value connects to: Membership_text
Connect a List
Connect dropdown list items: yes
Pick a connector: Dataset6
Labels and value connect to: Membership_text
I tried to create a new database that did contain only

And tried to use this dataset as filter for dataset6. Was this the way you suggested?
Sadly, I did not get the output in the textbox to update.
Creating a new collection is fine, but you didn’t have to. You can create two datasets tied to the same collection with the idea that one is connected to the dropdown, and the other is used to access the result of the filter.
With this setFilter code that I alluded to, dataset6 is the dataset not tied to the dropdown. The reason to use setFilter here is to specify which record’s data in the dataset that you want access to.
export function dropdown2_change(event) {
$w("#dataset6").setFilter( wixData.filter()
.eq("membership_text", event.target.value)
)
.then( () => {
let item = $w("#dataset6").getCurrentItem();
let membership_name= item.title;
let membership_bank= item.bank;
let membership_rate= item.rente;
$w("#text7").text =
"Your membership in " + membership_name + " can "
"give u an interest on " + membership_rate +
" with " + membership_bank + ".";
})
}
It works perfectly with that code. Thank you so much. Highly appreciated