I’m trying to use a dropdown menu as another form of header menu.
So when a visitor clicks on one of the option within the dropdown menu it takes them to another page within the dynamic pages of the site, is this possible?
I have a demo code below that I tried to do…
Could it be that this code doesn’t work on Dynamic Pages?
import wixLocation from 'wix-location';
export function classesDropdown_change() {
if ($w('#classesDropdown_change').value === 1) {
wixLocation.to(`Module-01/Module-N03`);
console.log("Going to Class #01");
}
if ($w('#classesDropdown_change').value === 2) {
wixLocation.to(`/Module-01/Teste-seus-Conhecimentos`);
console.log("Going to Class #02");
}
if ($w('#classesDropdown_change').value === 3) {
wixLocation.to(`/Module-01/Use-seu-website-para-atingir-suas-Metas---Dura%C3%A7%C3%A3o%3A-05%3A22`);
console.log("Going to Class #03");
}
}
Thanks, but for some reason the code don’t work on the site… It act like nothing happens. I added console.log to see if the code runs but, no messages are show in the Developer Console in preview mode. Is their something I’m missing something.
Could it be that this code doesn’t work on Dynamic Pages?
Hi Arthosmaciel,
I check your code, you should only have one $w.onReady on your page.
Every manipulation you want to apply on elements should be on that scope.
Looks like this:
Hi,
I checked your site, you have some syntax errors.
You have multiplies $w.onReady and $w(‘#dataset’).onReady. it looks they should be in the same scope.
$w.onReady(() => { // Only one $w.onReady
$w('#dynamicDataset').onReady(() => {
// all the relevant code for dynamicDataset
})
})
Sorry I don’t know where to add that part of the code…
Here the full code:
import wixLocation from "wix-location";
$w.onReady(() => { // Only one $w.onReady
$w('#dynamicDataset').onReady(() => {
$w.onReady(() => {
$w("#classesDropdown").onChange((event, $w) => {
let newValue = event.classDropdown.value;
if ($w('#classesDropdown_change').value === 1) {
wixLocation.to(`Module-01/Module-N03`);
console.log("Going to Class #01");
}
if ($w('#classesDropdown_change').value === 2) {
wixLocation.to(`/Module-01/Teste-seus-Conhecimentos`);
console.log("Going to Class #02");
}
if ($w('#classesDropdown_change').value === 3) {
wixLocation.to(`/Module-01/Use-seu-website-para-atingir-suas-Metas---Dura%C3%A7%C3%A3o%3A-05%3A22`);
console.log("Going to Class #03");
}
});
$w.onReady(() => { // Only one $w.onReady
$w('#dynamicDataset').onReady(() => {
$w("#classesDropdown").onChange((event, $w) => {
let newValue = event.classDropdown.value;
if ($w("#classesDropdown").value === 1) {
wixLocation.to(`Module-01/Module-N03`);
console.log("Going to Class #01");
}
if ($w("#classesDropdown").value === 2) {
wixLocation.to(`/Module-01/Teste-seus-Conhecimentos`);
console.log("Going to Class #02");
}
if ($w("#classesDropdown").value === 3) {
wixLocation.to(`/Module-01/Use-seu-website-para-atingir-suas-Metas---Dura%C3%A7%C3%A3o%3A-05%3A22`);
console.log("Going to Class #03");
}
});
});
});