If statement example


About

Depending on your specific use, you may need to add code to the Site Code Tab instead of the Page Code Tab at the bottom of your editor.  You can use an If statement after an event happens. You can see different events from an elements properties panel. You can either use the Properties Panel to trigger these events or you can use code. Below you will find both ways of triggering an If Statement.


 

Good to Know #1

The Code using Properties Panel


The code snippet example below shows an if statement used to show something if a value equals to something specific when a dropdown is selected or changed.



$w.onReady(function () {
 //
});

export function dropdown1_onChange() {
 let value = $w("#dropdown1").value;
 if (value === "Purple") {
        $w("#purpleTextBox").show(); //do this thing
    } else if (value !== "Purple") {
        $w("#purpleTextBox").hide(); //or else do this other thing
    }
}
    


The following example shows an If Statement when an element is empty after a button is clicked.



 $w.onReady(function () {
 //
});

export function submitButton_onClick() {
 let value = $w("#dropdown1"<