# simple show/hide button based on dataset Field Key value

**URL:** <https://forum.wixstudio.com/t/simple-show-hide-button-based-on-dataset-field-key-value/1649>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [February 11, 2021, 4:19pm UTC](https://forum.wixstudio.com/t/simple-show-hide-button-based-on-dataset-field-key-value/1649 "2021-02-11T16:19:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![info51165](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/info51165/32/26728_2.png) [@info51165](https://forum.wixstudio.com/u/info51165)\
**Post date:** [February 11, 2021, 4:19pm UTC](https://forum.wixstudio.com/t/simple-show-hide-button-based-on-dataset-field-key-value/1649/1 "2021-02-11T16:19:16Z")

</div>

Hi guys,

I have been searching and trying for a few days now but can’t seem to find the right answer to my question. Forgive me if this has been asked before, then please point me in the right direction.

I’m trying to understand how I can show or hide some page elements like an image, button or video player, based on values I get from the database, using custom code.

My database has movies in them (title, editor, year, runningtime, etc) and the only thing I want to do is hide a specific button on a Dynamic Page (the movie details page) when the Field Key (type: boolean) is TRUE.

So I would nee something in code like:

- get all database values for this film from the database
- if = TRUE hide 
- else show 

Tried hundreds of code snippets and combinations, but can’t seem to get this to work.

Please advise and thanx in advance!

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [February 11, 2021, 6:13pm UTC](https://forum.wixstudio.com/t/simple-show-hide-button-based-on-dataset-field-key-value/1649/2 "2021-02-11T18:13:23Z")

</div>

Of course you can:

1. Query the database collection with .eq(fieldtypename, true) and get all the matched results

2. if( results.items.length \> 0){$w(“button”).hide();}else{$w(“button”).show();}  
See:  
[https://www.wix.com/velo/reference/wix-data/query](https://www.wix.com/velo/reference/wix-data/query)  
[https://www.wix.com/velo/reference/$w/hiddenmixin/show](https://www.wix.com/velo/reference/$w/hiddenmixin/show)  
[https://www.wix.com/velo/reference/$w/hiddenmixin/hide](https://www.wix.com/velo/reference/$w/hiddenmixin/hide)

---

<div class="post-metadata">

**Author:** ![info51165](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/info51165/32/26728_2.png) [@info51165](https://forum.wixstudio.com/u/info51165)\
**Post date:** [February 11, 2021, 7:50pm UTC](https://forum.wixstudio.com/t/simple-show-hide-button-based-on-dataset-field-key-value/1649/3 "2021-02-11T19:50:51Z")

</div>

Hi JD, thank you for your reply. I couldn’t get it to work with your example, but managed to figure it out anyway. This is how I solved it;

$w.onReady(() =\> {  
$w( “#mydynamicdatasetname” ).onReady(() =\> {  
**const** item = $w( “#mydynamicdatasetname” ).getCurrentItem();  
**if** (item.myfieldkeyname) {  
$w( “#element1” ).expand();  
$w(“#element2”).expand();  
}  
});  
});

So now the dynamic page loads, looks if there is a value in “wyfieldkeyname”. If there is, it shows element 1 and 2 on this page.

A very important thing to keep in mind that for this to work, the elements both **have to be marked as “collapsed” in the Deafult Values pannel**.

---

<div class="post-metadata">

**Author:** ![payment](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/payment/32/18119_2.png) [@payment](https://forum.wixstudio.com/u/payment)\
**Post date:** [February 12, 2021, 2:12pm UTC](https://forum.wixstudio.com/t/simple-show-hide-button-based-on-dataset-field-key-value/1649/4 "2021-02-12T14:12:24Z")

</div>

Hey Stefan, thanks for figuring this out. I’ve been hunting around for a way to do this too and thanks to your method mine is working too 🙂

---

<div class="post-metadata">

**Author:** ![estac-343](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/estac-343/32/9574_2.png) [@estac-343](https://forum.wixstudio.com/u/estac-343)\
**Post date:** [July 19, 2023, 3:39pm UTC](https://forum.wixstudio.com/t/simple-show-hide-button-based-on-dataset-field-key-value/1649/5 "2023-07-19T15:39:53Z")

</div>

Hi estefano, can this code be written directly in the “page code tab” or do I have to create a js file in the backend? My understanding is that Wix collections cannot be accessed from the code tab of the page.  
Thank you so much
