Now on day 3 of trying to figure this out -
Question:
I have 2 drop-down boxes on my main page populated from a database query (Drop down #1 is State & Drop down #2 is Lake). the 2nd drop-down is based on what the user selects in the first drop-down box. These 2 drop-downs are working great.
I’ve added a button at the bottom called “Shop Now” which i want to direct the user to based on the specific lake the user selects in the 2nd drop-down. Sounds like it should be an easy thing to do??
Product:
Not sure what product this is - just logging into the Wix editor to edit my website
What are you trying to achieve:
[Explain the details of what you are trying to achieve. The more details you provide, the easier it is to understand what you need.]
What have you already tried:
I’ve tried everything I could find on the web regarding trying to get this to work.
Here is my current code that runs my drop-downs and enables the button:
import wixLocation from 'wix-location';
import wixData from 'wix-data';
let filter;
let location;
$w.onReady(function () {
initPage();
});
async function initPage() {
const StateLakes = {};
wixData.query('StateDB')
.ascending('title')
.find()
.then(results => {
const stateOptions = results.items.map(state => ({ label: state.title, value: state._id }));
$w('#dropdownstate').options = stateOptions;
});
$w('#dropdownstate').onChange(async() => {
let hasLakes = false;
const selectedState = $w('#dropdownstate').value;
if (StateLakes[selectedState]) {
hasLakes = true;
$w('#dropdownlake').options = StateLakes[selectedState];
} else {
const results = await wixData.query('LakeDB1')
.eq('state', selectedState)
.ascending('title')
.find()
if (results.length > 0) {
hasLakes = true;
const lakeOptions = results.items.map(lake => ({ label: lake.title, value: lake._id }));
$w('#dropdownlake').options = lakeOptions;
StateLakes[selectedState] = lakeOptions;
}
}
if (hasLakes) {
$w('#dropdownlake').selectedIndex = undefined;
$w('#dropdownlake').expand();
$w('#button43').disable();
} else {
$w('#dropdownlake').collapse();
$w('#button43').enable();
}
});
$w('#dropdownlake').onChange(() => {
$w('#button43').enable();
});