Database Dropdown List with button

I need help setting up a dropdown and a button, the first time I tried it worked, I followed the steps from this post - https://www.wix.com/velo/forum/community-discussion/dropdown-box-url-button-linked-database
Everytime I click my button. It takes me to the first URL on my database, not the corresponding URL on the database
This is my code -
import wixData from ‘wix-data’ ;
import wixLocation from ‘wix-location’ ;

export function dropdown1_change(event, $w) {
$w( “#dataset1” ).setCurrentItemIndex(event.target.selectedIndex)

}
export function button1_click(event, $w) {
wixLocation.to($w( “#dataset1” ).getCurrentItem().url);

}

How do I change it so it links to the correct one?

This is how my dropdown, button and dataset are set up

Already tried to disconnect your button from DATASET?

I tried now but it doesn’t work

Try this one and take also a look into the CONSOLE!
Which resulst and messages do you get there?

import wixData from'wix-data'; 
import wixLocation from'wix-location';

$w.onReady(()=>{
    $w("#dataset1").onReady(()=>{
        $w('#dropdown1').onChange((event)={console.log("DropDown-changed")
           console.log(event.target.selectedIndex)
           $w("#dataset1").setCurrentItemIndex(event.target.selectedIndex)
        })
    })
        
    $w("#button1").onClick(()=>{console.log("Button-clicked")
        wixLocation.to($w("#dataset1").getCurrentItem().url)
    })
})

Do your button-actions work ?

1 Like

@russian-dima Thank you! I managed to make it work

@rebecarpop
Do not forget to like it, if you really liked it :wink:

Good luck and happy coding.