# JavaScript lifecycle in a landing page

**URL:** <https://community.hubspot.com/t/javascript-lifecycle-in-a-landing-page/12635>\
**Category:** APIs & Integrations\
**Tags:** forms\
**Created:** [December 19, 2018, 12:37pm UTC](https://community.hubspot.com/t/javascript-lifecycle-in-a-landing-page/12635 "2018-12-19T12:37:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![WTWJamie](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/wtwjamie/32/102437_2.png) [@WTWJamie](https://community.hubspot.com/u/WTWJamie)\
**Post date:** [December 19, 2018, 12:37pm UTC](https://community.hubspot.com/t/javascript-lifecycle-in-a-landing-page/12635/1 "2018-12-19T12:37:10Z")

</div>

I’m trying to use a form within a template. I want to style this form using Materialize.css so that it can abide to our company’s branding guidelines. This means that when the form loads, I need to execute this JavaScript  
M.AutoInit();  
to tell Materialize to initialize the form. My problem is that when I include this JavaScript before the closing body tag, it never seems to fire. I’m assuming this is either because

> The Materialize dependency hasn’t loaded in by this point  
> The form hasn’t rendered by this point (I think the HubSpot forms embed React and render as their own thing?)

What I’m looking for is a hook to either catch my dependency loading, or the form itself loading, and follow it up with my JS call. Is there any such thing?

On making this less of a guessing game, is there also a way to prevent them pre-processing my JavaScript so that I can use Console.Log() for debugging?

---

<div class="post-metadata">

**Author:** ![IsaacTakushi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/isaactakushi/32/70387_2.png) [@IsaacTakushi](https://community.hubspot.com/u/IsaacTakushi)\
**Post date:** [December 20, 2018, 4:45pm UTC](https://community.hubspot.com/t/javascript-lifecycle-in-a-landing-page/12635/2 "2018-12-20T16:45:39Z")

</div>

Welcome, @WTWJamie!

Could you add your script to an [`onFormReady`](https://developers.hubspot.com/global-form-events) event in the form’s embed code? The form would be loaded at that point.

---

<div class="post-metadata">

**Author:** ![WTWJamie](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/wtwjamie/32/102437_2.png) [@WTWJamie](https://community.hubspot.com/u/WTWJamie)\
**Post date:** [December 28, 2018, 1:48pm UTC](https://community.hubspot.com/t/javascript-lifecycle-in-a-landing-page/12635/3 "2018-12-28T13:48:33Z")

</div>

Thanks Isaac, that looks perfect but I’m not creating the form via the API, I’m just referencing it in Design Manager. My end goal is to make a template for my boss that fits our design spec, is there a better tool for me to be making templates in? Or can I access the Form’s embed code from within Design Manager?

---

<div class="post-metadata">

**Author:** ![IsaacTakushi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/isaactakushi/32/70387_2.png) [@IsaacTakushi](https://community.hubspot.com/u/IsaacTakushi)\
**Post date:** [December 28, 2018, 2:40pm UTC](https://community.hubspot.com/t/javascript-lifecycle-in-a-landing-page/12635/4 "2018-12-28T14:40:11Z")

</div>

Hey, @WTWJamie.

[Global form events](https://developers.hubspot.com/global-form-events) like `onFormReady` are JavaScript events you can add to a form’s embed code without using APIs.

You won’t be able to access a form’s embed code in either design manager or the page editor if you’re using the default _Form_ module. Instead, you’ll have to [embed the form](https://knowledge.hubspot.com/articles/kcs_article/forms/how-can-i-share-a-hubspot-form-if-im-using-an-external-site#add-the-form-embed-code) in either a _Custom HTML_ or _Rich Text_ module and add the desired event.

Let me know if I’m still misunderstanding you!

---

<div class="post-metadata">

**Author:** ![WTWJamie](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/wtwjamie/32/102437_2.png) [@WTWJamie](https://community.hubspot.com/u/WTWJamie)\
**Post date:** [December 28, 2018, 3:09pm UTC](https://community.hubspot.com/t/javascript-lifecycle-in-a-landing-page/12635/5 "2018-12-28T15:09:56Z")

</div>

That’s perfect, all working now. Thanks a ton  
 ![smiley.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/5/e/5ece32cc997517bd0f7529e47698e55a18eaae82.png)

---

<div class="post-metadata">

**Author:** ![IsaacTakushi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/isaactakushi/32/70387_2.png) [@IsaacTakushi](https://community.hubspot.com/u/IsaacTakushi)\
**Post date:** [December 28, 2018, 3:12pm UTC](https://community.hubspot.com/t/javascript-lifecycle-in-a-landing-page/12635/6 "2018-12-28T15:12:29Z")

</div>

Glad I could help, Jamie-Lee!
