# Using onclick to set display to block

**URL:** <https://community.hubspot.com/t/using-onclick-to-set-display-to-block/63374>\
**Category:** CMS Development\
**Tags:** starter\
**Created:** [August 19, 2022, 6:46pm UTC](https://community.hubspot.com/t/using-onclick-to-set-display-to-block/63374 "2022-08-19T18:46:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![IMckell](https://avatars.discourse-cdn.com/v4/letter/i/3ec8ea/32.png) [@IMckell](https://community.hubspot.com/u/IMckell)\
**Post date:** [August 19, 2022, 6:46pm UTC](https://community.hubspot.com/t/using-onclick-to-set-display-to-block/63374/1 "2022-08-19T18:46:59Z")

</div>

I’m working on a simple module where you can click a button and it will set the display of a “pop-up form” to block. The form itself works just fine. I got the pop up to work with a load event listener, but now I need it to appear after a button click. This very simple action seems so difficult with hubspot, or maybe I’m just making a dumb mistake. Can you help me out?

here’s the code

\<button class=“cryptoChartButton” onclick=“DisplayPopUp()” type=“button”\>{% inline\_rich\_text field=“pop\_up\_button\_text” value=“{{ module.pop\_up\_button\_text }}” %}\</button\>

{% set href = module.link\_cryptochart.url.href %}  
{% if module.link\_cryptochart.url.type is equalto “EMAIL\_ADDRESS” %}  
{% set href = “mailto:” + href %}  
{% endif %}  
\<a href=“{{ href }}”  
{% if module.link\_cryptochart.open\_in\_new\_tab %}target=“\_blank”{% endif %}  
{% if module.link\_cryptochart.rel %}rel=“{{ module.link\_cryptochart.rel }}”{% endif %}  
\>  
{% inline\_rich\_text field=“link\_button\_text” value=“{{ module.link\_button\_text }}” %}  
\</a\>  
{% set no\_title = True %}

{% if module.form\_pop\_up.form\_id %}  
{% form  
form\_key=‘{{ name }}’,  
form\_to\_use=‘{{ module.form\_pop\_up.form\_id }}’,  
no\_title=‘{{ no\_title }}’,  
%}  
{% endif %}

\<script\>  
function DisplayPopUp(){  
document.getElementsByTagName(“form”).style.display = “block”;  
}  
\</script\>

\<style media=“screen”\>  
\*,  
\*:before,  
\*:after{  
padding: 0;  
margin: 0;  
box-sizing: border-box;  
}

form{  
opacity: 1;  
animation-name: fadeInOpacity;  
animation-iteration-count: 1;  
animation-timing-function: ease-in;  
animation-duration: 1.5s;  
background-color: rgba(220, 220, 220, 0.9);  
display: none !important;  
position: fixed;  
z-index: 10000000000;  
position: fixed;  
width: auto;  
max-height: 700px;  
left: 50%;  
top: 50%;  
transform: translate(-50%, -50%);  
}

@keyframes fadeInOpacity {  
0% {  
opacity: 0;  
}  
100% {  
opacity: 1;  
}

\</style\>

---

<div class="post-metadata">

**Author:** ![BarryGrennan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/barrygrennan/32/97794_2.png) [@BarryGrennan](https://community.hubspot.com/u/BarryGrennan)\
**Post date:** [August 20, 2022, 12:26am UTC](https://community.hubspot.com/t/using-onclick-to-set-display-to-block/63374/2 "2022-08-20T00:26:03Z")

</div>

I don’t think it’s a hubspot issue. I think it’s this line.

`document.getElementsByTagName("form").style.display = "block";`

If you wrap the form in a div and target it by id instead it’s working

```lia-code-sample
<button class="cryptoChartButton" onclick="DisplayPopUp()" type="button">POPUP</button>

{% set href = module.link_cryptochart.url.href %}
{% if module.link_cryptochart.url.type is equalto "EMAIL_ADDRESS" %}
{% set href = "mailto:" + href %}
{% endif %}
<a href="{{ href }}"
{% if module.link_cryptochart.open_in_new_tab %}target="_blank"{% endif %}
{% if module.link_cryptochart.rel %}rel="{{ module.link_cryptochart.rel }}"{% endif %}
>
{% inline_rich_text field="link_button_text" value="{{ module.link_button_text }}" %}
</a>

{% set no_title = True %}

<div id="form-holder">
 HERE'S MY FORM!!!
{% form
form_key='{{ name }}',
form_to_use='{{ module.form_pop_up.form_id }}',
no_title='{{ no_title }}',
%} 
</div>

{% require_js position="footer" %}
<script>
function DisplayPopUp(){
document.getElementById("form-holder").style.display = "block";
}
</script>
{% end_require_js %}

<style media="screen">
*,
*:before,
*:after{
padding: 0;
margin: 0;
box-sizing: border-box;
}

#form-holder {
opacity: 1;
animation-name: fadeInOpacity;
animation-iteration-count: 1;
animation-timing-function: ease-in;
animation-duration: 1.5s;
background-color: rgba(220, 220, 220, 0.9);
display: none;
position: fixed;
z-index: 10000000000;
position: fixed;
width: auto;
max-height: 700px;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}

@keyframes fadeInOpacity {
0% {
opacity: 0;
}
100% {
opacity: 1;
}

</style>

```

Note: I also pulled out the conditional around the form but that’s just because I wasn’t going to create a whole module to test it 🙂

* * *

 ![profile2022a.jpg](https://d2qpr2jzcazej7.cloudfront.net/original/2X/7/7273a34ccfe3489fceebc8a36eca751481b59531.jpeg)

**Barry Grennan**

[Freelance HubSpot CMS Developer](https://www.seoanseo.ca?utm_source=HubSpotCommunity)

[Website](https://www.seoanseo.ca?utm_source=HubSpotCommunity) | [Contact](https://www.seoanseo.ca/#contact?utm_source=HubSpotCommunity)

---

<div class="post-metadata">

**Author:** ![IMckell](https://avatars.discourse-cdn.com/v4/letter/i/3ec8ea/32.png) [@IMckell](https://community.hubspot.com/u/IMckell)\
**Post date:** [August 22, 2022, 3:01pm UTC](https://community.hubspot.com/t/using-onclick-to-set-display-to-block/63374/3 "2022-08-22T15:01:03Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![BarryGrennan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/barrygrennan/32/97794_2.png) [@BarryGrennan](https://community.hubspot.com/u/BarryGrennan)\
**Post date:** [August 22, 2022, 5:58pm UTC](https://community.hubspot.com/t/using-onclick-to-set-display-to-block/63374/4 "2022-08-22T17:58:41Z")

</div>

No worries!

* * *

 ![profile2022a.jpg](https://d2qpr2jzcazej7.cloudfront.net/original/2X/7/7273a34ccfe3489fceebc8a36eca751481b59531.jpeg)

**Barry Grennan**

[Freelance HubSpot CMS Developer](https://www.seoanseo.ca?utm_source=HubSpotCommunity)

[Website](https://www.seoanseo.ca?utm_source=HubSpotCommunity) | [Contact](https://www.seoanseo.ca/#contact?utm_source=HubSpotCommunity)
