Change the state box based on the dropdown selection and then click the button

This button functions to change the state box based on the dropdown selection
How to make ? Help me

$w.onReady(() => {
$w(‘#button1’).onClick(() => {
$w(“#dropdownSewa”).onChange(event => {
console.log(“Baru”)
$w(“#statebox1”).changeState(‘state2’);
});
});});

Screenshot 2024-02-17 160318

$w.onReady(() => {
    $w(‘#button1’).onClick((e)=> {
        $w(“#dropdownSewa”).onChange((e)=> {
            console.log($w(“#dropdownSewa”).value);
            console.log($w(“#dropdownSewa”).selectedIndex);
            $w(“#statebox1”).changeState(‘state2’);
        });
    });
});

Now you create some if-else-conditions…

if(.....) {........}
else {......}
if($w(“#dropdownSewa”).value) {cosnole.log(.............);}
else {cosnole.log(.............);}
if($w(“#dropdownSewa”).selectedIndex === 0) {cosnole.log(.............);}
else if($w(“#dropdownSewa”).selectedIndex === 1) {cosnole.log(.............);}
else if($w(“#dropdownSewa”).selectedIndex === 2) {cosnole.log(.............);}
else {cosnole.log(.............);}

… and so on…

There are also more direct ways of how to do that, but for understandings, this example should be enough.

I still don’t understand
Can you help make it?
After that I will study

I’ve used this successfully

export function button1_click(event) {
if ($w(‘#dropdownSewa’).value === “Baru”) {
$w(‘#statebox1’).changeState(‘state2’);
}
if ($w(‘#dropdownSewa’).value === “Tetap”) {
$w(‘#statebox1’).changeState(‘state3’);
}
if ($w(‘#dropdownSewa’).value === “DS”) {
$w(‘#statebox1’).changeState(‘state4’);
}}

Thank you for helping me

1 Like