# Manipulate Hubspot Forms after loading (jquery)

**URL:** <https://community.hubspot.com/t/manipulate-hubspot-forms-after-loading-jquery/47167>\
**Category:** APIs & Integrations\
**Tags:** forms\
**Created:** [November 18, 2021, 9:51am UTC](https://community.hubspot.com/t/manipulate-hubspot-forms-after-loading-jquery/47167 "2021-11-18T09:51:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mhdev](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@mhdev](https://community.hubspot.com/u/mhdev)\
**Post date:** [November 18, 2021, 9:51am UTC](https://community.hubspot.com/t/manipulate-hubspot-forms-after-loading-jquery/47167/1 "2021-11-18T09:51:10Z")

</div>

Hello!

Im trying to manipulate a Hubspot Form after it loaded (change input values e.g.). I found something like this: [https://community.hubspot.com/t5/APIs-Integrations/Manipulating-forms-after-loading-on-Hubspot-landing-pages/m-p/399559#M39498](https://community.hubspot.com/t5/APIs-Integrations/Manipulating-forms-after-loading-on-Hubspot-landing-pages/m-p/399559#M39498)

So I tried some basic stuff:

```lia-code-sample
 window.addEventListener('message', event => {
 if (event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormReady') {
 $('input[name="firstname"]').val('Brian').trigger('change');
 console.log("Form loaded!");
 }
 });

```

There is no error, it says “form loaded!” in console and thats it.

I tried the same construct with this like its mentioned here: [HubSpot Developer Documentation - HubSpot docs](https://developers.hubspot.com/docs/api/faq)

```lia-code-sample
hbspt.forms.create({
 portalId: 'XXXX',
 formId: 'XXXX',
 onFormSubmit: function($form) {
 $('input[name="firstname"]').val('Brian').change();
 } 
}); 

```

Its the same, I cant manipulate the Hubspot Form. There is an input field with a name “firstname”.

Am i doing something wrong or is their a better method to achieve what i try to do?

Regards

Michael

---

<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:** [November 18, 2021, 9:18pm UTC](https://community.hubspot.com/t/manipulate-hubspot-forms-after-loading-jquery/47167/2 "2021-11-18T21:18:31Z")

</div>

@mhdev

Your second codeblock using onFormSubmit rather than onFormReady.

---

<div class="post-metadata">

**Author:** ![mhdev](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@mhdev](https://community.hubspot.com/u/mhdev)\
**Post date:** [November 19, 2021, 8:29am UTC](https://community.hubspot.com/t/manipulate-hubspot-forms-after-loading-jquery/47167/3 "2021-11-19T08:29:15Z")

</div>

Oh, I copied an example from the documentation.

The code i am using is this:

```lia-code-sample
hbspt.forms.create({
 region: "xxx",
 portalId: "xxx",
 formId: "xxx",
 onFormReady: function($form) {
 $('input[name="firstname"]').val('Brian').change();
 }
 });

```

So i tested it with onFormReady and it doesnt work either for me.

---

<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:** [November 19, 2021, 2:32pm UTC](https://community.hubspot.com/t/manipulate-hubspot-forms-after-loading-jquery/47167/4 "2021-11-19T14:32:49Z")

</div>

Make sure your are including the script above the forms create.

Check out [this pen](https://codepen.io/billyoncetoldme/pen/KKvEaEb) for an example of it working

---

<div class="post-metadata">

**Author:** ![mhdev](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@mhdev](https://community.hubspot.com/u/mhdev)\
**Post date:** [November 19, 2021, 2:50pm UTC](https://community.hubspot.com/t/manipulate-hubspot-forms-after-loading-jquery/47167/5 "2021-11-19T14:50:32Z")

</div>

Thank your for your answer!

Your script is working like a charm, the only difference to mine (i did inlcude the js script) is that my form is embedded into an iframe and your form is not. I guess that is the problem i have.

Can you embed the form without an iframe and if so how?

Thanks in advance!

Michael

---

<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:** [November 19, 2021, 2:52pm UTC](https://community.hubspot.com/t/manipulate-hubspot-forms-after-loading-jquery/47167/6 "2021-11-19T14:52:18Z")

</div>

@mhdev

Ah! Yep, that would do it.

In the form options, you will see a toggle to set it to raw html. Select that and I think you will off to the races

---

<div class="post-metadata">

**Author:** ![mhdev](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@mhdev](https://community.hubspot.com/u/mhdev)\
**Post date:** [November 22, 2021, 7:35am UTC](https://community.hubspot.com/t/manipulate-hubspot-forms-after-loading-jquery/47167/7 "2021-11-22T07:35:07Z")

</div>

Awesome, thank you so much for your help!

Have a great week.

Kind regards

Michael
