I’ve put a drop down box on my page that looks like this:
I want the ‘go’ button to be the trigger to launch the link in my database.
The dropdown down has been set up like this:
And my ‘go’ button has been set up like this:
However, everytime I click ‘go’. It takes me to the first URL on my Database, not the corresponding URL on the database. How do I change it so it links to the correct one?
I wondering if anyone has spotted this post? It seems like it should be a fairly easy thing to fix. I guessing I’ve just miss-read one of your help pages somewhere?
What you’re trying to do is indeed not too difficult, but you’ll need to write some code.
You need to create a onChange event handler for the dropdown that looks something like this:
import wixLocation from 'wix-location';
// the above line must be at the top of your code
// you need to connect this function to your dropdown using the properties panel
export function dropdown_change(event, $w) {
$w("#dataset1").setCurrentItemIndex(event.target.selectedIndex)
.then( () => {
wixLocation.to($w("#dataset1").getCurrentItem().url);
} );
}
Okay, it’s hard to be sure what’s going on. Did you wire the function correctly using the properties panel? Are there any error messages in the code panel? If so, please attach a screenshot.
Woah, hold on a second. What’s going on there on the first 317 lines of code? If there is anything up there, and I assume there is, you’ll need to move the import line (318) all the way to the top of your code. Imports need to be the first things that happen in the code.
Also, (my bad) I forgot to mention that you need to change the .url on line 322 to the field key of the column in your collection that contains the URLs. Looks from your screenshots that it might be .links .
Hi Thomas,
Can you post the full code above where you have the button click controlling it instead of the selection from the dropdown. I can’t seem to make it work and I can really use this function.
Thank you
import wixData from 'wix-data';
import wixLocation from 'wix-location';
This section selects the current item in your dataset:
Change dataset1 with the name of the dataset you are wanting to search through.
export function dropdown1_change(event, $w) {
$w("#dataset1").setCurrentItemIndex(event.target.selectedIndex)
}
//when you click the item in your dropdown,
//it selects the corresponding item row in the dataset
//*if you don't do this it will just use the first item in your dataset*
Attach this to the button you want to use as your “Click to Search”:
Change dataset1 with the same name as the above dataset.
Change links to the column name in your dataset (the one with the URL in it)
export function button32_click(event, $w) {
wixLocation.to($w("#dataset1").getCurrentItem().links);
}
//previous code selects the row
//this code selects the URL column
//then opens the browser page to the link you have in the column
Hi Thomas,
Thank you for your help.
I’ve attempted to do this but i’m getting error codes and it’s not working.
The code where I have the drop down controlling works fine and looks like this: