How to write if statements with text boxes containing URLs

Hi, I have a textbox in a dynamic page which displays url from my dataset. In the dataset some recods contain a url while some do not.
I want a button to be displayed if this textbox contains a url.

The below is the code I used, but it’s not working. I shall appreciate if you could let me know how to fix this.
I kept button’s property as “Hidden on load”

import wixData from ‘wix-data’ ;
export function textbox_viewportEnter(event) {
let urlvalue=$w( “#textbox” ).text;
if (urlvalue=== ‘’ ) {
$w( “#button” ).hide()
} else {$w( “#button” ).show()}
}

Hey,

We have a great tutorial that shows you how to hide a video player on a page if the video field for an item in a database is empty.

You could follow this tutorial and change it to suit your needs to show a hidden button if the field has a value.

Corvid Tutorial: Hiding a Video Player When There Is No Video to Play

It could end up looking something like this:

$w.onReady(() => {
    $w("#myDataset").onReady(() => {
 // Gets the current item properties and stores them in a variable called item
 const item = $w("#myDataset").getCurrentItem();
 // Checks if the current item has a value in the "url" field
 if (item.url) {
 // Shows the button if there is a value for "url"
            $w("#button").show();
        }
    });
});

You could also do closer to the tutorial and set the button to show on load and then only hide it if the URL field is empty.

Hope this helps!

Dara | Corvid Team

Thank you very much!

IF you want to understand why Dara´s solution works, and yours did not, look up “falsy” and “truthy” in Javascript on Google.