# Trigger code when submitting form

**URL:** <https://community.hubspot.com/t/trigger-code-when-submitting-form/29080>\
**Category:** APIs & Integrations\
**Tags:** forms\
**Created:** [December 11, 2020, 6:16pm UTC](https://community.hubspot.com/t/trigger-code-when-submitting-form/29080 "2020-12-11T18:16:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![CSerna](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/cserna/32/74736_2.png) [@CSerna](https://community.hubspot.com/u/CSerna)\
**Post date:** [December 11, 2020, 6:16pm UTC](https://community.hubspot.com/t/trigger-code-when-submitting-form/29080/1 "2020-12-11T18:16:07Z")

</div>

Hi everyone,

Can a JavaScript code be triggered when clients click on submit in forms?

I have the code but I don’t know where to place it.

Thanks,

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [December 14, 2020, 2:54pm UTC](https://community.hubspot.com/t/trigger-code-when-submitting-form/29080/2 "2020-12-14T14:54:28Z")

</div>

Hello @CSerna !

Welcome to the Community!

You will want to put it within the **onFormSubmit** callback. You can see an example in the docs [here](https://legacydocs.hubspot.com/docs/methods/forms/advanced_form_options)
