You need to check if it’s undefined because when there is no value it will be undefined it will not gonna be empty string. Also, if you have default selected item from dropdown it will not gonna be undefined.
Example:
$w.onReady(function () {
let value = $w("#dropdown").value;
if (value === undefined) {
$w('#button').hide();
} else {
$w('#button').show();
}
});
Hi thanks for your time! the dropdown is connected to a database but it doesn’t show anything by default, try your code but still the same problem. I tried with the clean code page and it still doesn’t work
hello Ninja, I did see that detail but it still happens that when changing any drop-down menu the button appears. What I'm trying to do is make that button only appear when all dropdowns are complete.
Next time be more precisious with your wished functions.
Anybody knows what you are trying to achieve
I changed the example.
This time you have a “CHECK-FUNCTION” including a counter, which counts all not used/activated/valued DropDowns.
If it founds one, the counter will COUNT-UP. If at the END of the LOOP, the counter is bigger than → 1, what does it mean ???
let DROPDOWN = [];
DROPDOWN[0] = "#dropdown0";
DROPDOWN[1] = "#dropdown1";
DROPDOWN[2] = "#dropdown2";
DROPDOWN[3] = "#dropdown3";
DROPDOWN[4] = "#dropdown4";
$w.onReady(function() {
$w(DROPDOWN[0]).onChange((event)=> {let value = $w(DROPDOWN[0]).value; check_DropDowns(); console.log(event.target.id+" changed!!!");});
$w(DROPDOWN[1]).onChange((event)=> {let value = $w(DROPDOWN[1]).value; check_DropDowns(); console.log(event.target.id+" changed!!!");});
$w(DROPDOWN[2]).onChange((event)=> {let value = $w(DROPDOWN[2]).value; check_DropDowns(); console.log(event.target.id+" changed!!!");});
$w(DROPDOWN[3]).onChange((event)=> {let value = $w(DROPDOWN[3]).value; check_DropDowns(); console.log(event.target.id+" changed!!!");});
$w(DROPDOWN[4]).onChange((event)=> {let value = $w(DROPDOWN[4]).value; check_DropDowns(); console.log(event.target.id+" changed!!!");});
});
function check_DropDowns() {let counter = 0;
for (let i = 0; i < DROPDOWN.length; i++) {
if(!$w(DROPDOWN[i]).value) {counter=counter+1}
if(i === DROPDOWN.length-1) {
if(counter>0) {console.log("Not all DropDowns checked!"); $w('#button52').show();}
else {console.log("All DropDowns checked!"); $w('#button52').hide();}
}
}
}
Of course you can optimize it even more, but i think this should work for you.
And in future ALWAYS describe your wished function as most detailed as possible, because there are 1000 of different code-variations which can be your solution and it depends all on your detailed description of your issue.