redirect user to page based on a response in the dropdown

I have a table with names and each name has a specific link, as I do for when the name is selected and user clicks the button to search the site redirect the user to the page related to the name that is in the table.
I do not know how to do it, please help me out.

Hi,
I’m a bit confused. Do you want the site visitor to be redirected to the page when he clicks on the table or change the dropdown?
Can you please send us a screenshot of the page so that we can better understand what you were referring?

Thanks,
Tal.

1 Like

Hi Tal, sorry for the delay and thanks for answering me
then the idea is this:

Hi,
You can query the database, check if the user selected the relevant city / state and redirect to the page.
Here’s a code snippet:

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

$w.onReady(function () {
	$w('#searchBtnId').onClick(()=>{
		//collection name
		wixData.query("vendedores")
		//first dropdown value
		.eq("state", $w('#stateDropdownID').value) 
		//second dropdown value
		.eq("cidades",$w('#stateDropdownID').value )
		.find() 
		.then( (results) => { 
			let firstItem = results.items[0];
			//redirect to the link 
			wixLocation.to(firstItem.link);
		}) 
		.catch( (err) => { 
			let errorMsg = err; 
		} );
	});
});

Click here to learn more about the to function of Wix Location API.
Click here to learn more about the query function of Wix Data API.

Should the issue persists, please send us the site URL and the page name (the name, not the page URL…) so that we can have a look.

Good luck,
Ta.

2 Likes

Hi Tal Thank you for answering me
I put the code and there was not any error in the console, and simply when the button is clicked it does not happen at all, apparently it’s all right and already tried to make it work for more than 4 hours before coming here to talk to you again.
I put the filter just for the city to make it easy, but it still did not work
this is the url of the site: https://www.importadoragaribaldi.com/teste-1

Do you have any synchronization that needs to be done?

Hi,
I’ve accessed your editor and there was no code in the page section:


Can you please clarify to which page the code was added so that I can have a look (page name)?

Thanks,
Tal.

1 Like

Sorry I was using another page as a test, and I forgot to load the code on the page I needed.
I need on.click to save the information in the “cadastro_de_clientes” collection and then store the user to the page referring to the seller according to the city he chose, referring to the “vendedores” collection.
(the form is already connected to the collection “cadastro_de_clientes” and is linked by the '#enviar button).

It should be easy, but how do I when a state is chosen in the dropdown #states the dropdown #cidades is loaded to the cities for #states that was chosen?
(I already have all states and cities in an excel spreadsheet).

I will start and study to be able to learn, but my problem now is that my time is very very short, thank you very much if you can help me again;)
(I’m using a translator for our conversation)

?

Hi,
I recommend checking out the Cascading Form example to display the relevant cities after choosing a country from a dropdown.

Good luck,
Tal.

Thiago, você conseguiu fazer essa função? Estou travada no mesmo ponto