# Simple show/hide text box on button click

**URL:** <https://forum.wixstudio.com/t/simple-show-hide-text-box-on-button-click/2696>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [April 23, 2021, 1:45am UTC](https://forum.wixstudio.com/t/simple-show-hide-text-box-on-button-click/2696 "2021-04-23T01:45:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![poiqwe](https://avatars.discourse-cdn.com/v4/letter/p/c5a1d2/32.png) [@poiqwe](https://forum.wixstudio.com/u/poiqwe)\
**Post date:** [April 23, 2021, 1:45am UTC](https://forum.wixstudio.com/t/simple-show-hide-text-box-on-button-click/2696/1 "2021-04-23T01:45:14Z")

</div>

I’d like to have a single button toggle on/off two boxes of text (one hides and the other shows).

Here’s my code, I have no clue what I’m doing 😅:

export function button2\_click(event) {

if ($w( “#box19” ).hidden) **true** ;{  
$w( “#box19” ).show();  
$w( “#box28” ).hide();

```
} 

```

if ($w( “#box19” ).hidden) **false** ;{  
$w( “#box19” ).hide();  
$w( “#box28” ).show();  
}  
}

It’s similar to this, but with a single button, and text boxes, not images:  
[https://www.wix.com/velo-examples/show-hide](https://www.wix.com/velo-examples/show-hide)  
(also how do I even make use of this ^ resource?)

Thanks 😀

---

<div class="post-metadata">

**Author:** ![giri-zano](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/giri-zano/32/80469_2.png) [@giri-zano](https://forum.wixstudio.com/u/giri-zano)\
**Post date:** [April 23, 2021, 3:19am UTC](https://forum.wixstudio.com/t/simple-show-hide-text-box-on-button-click/2696/2 "2021-04-23T03:19:18Z")

</div>

Johnson, I would not worry about it too much, for we all adhered to the ChaCha-design principle at a certain stage (Cluelessly Horsing Around, Creating Hopeless Applications). But, with a bit of luck, determination and some help, you’ll get past that.  
Try this:

```javascript
export function button2_click(event) {
 if ($w("#box19").hidden) {
 $w("#box19").show();
 $w("#box28").hide();
    }
 else {
 $w("#box19").hide();
 $w("#box28").show();
    }
}

```

(I didn’t test this, but it should be OK or close).

Read this: [https://www.wix.com/velo/forum/tips-tutorials-examples/giri-gives-a-fac-1-falsy-thruthy-and-tri-valued-booleans](https://www.wix.com/velo/forum/tips-tutorials-examples/giri-gives-a-fac-1-falsy-thruthy-and-tri-valued-booleans) to understand.

And another thing: don’t use button\_2, box19, etc. If you look at this code again after a year, you will have no clue whatsoever what they mean. It’s better to give them speaking names, like “btnToggle” , “boxWhatever”, and so forth.

---

<div class="post-metadata">

**Author:** ![poiqwe](https://avatars.discourse-cdn.com/v4/letter/p/c5a1d2/32.png) [@poiqwe](https://forum.wixstudio.com/u/poiqwe)\
**Post date:** [April 23, 2021, 9:56am UTC](https://forum.wixstudio.com/t/simple-show-hide-text-box-on-button-click/2696/3 "2021-04-23T09:56:45Z")

</div>

Thank you so much! Worked perfectly. And thank you for the tip, that seems like good practice to save me from a lot of headaches in the future. Cheers 🙂
