# Customize default field values for form Embed code

**URL:** <https://community.hubspot.com/t/customize-default-field-values-for-form-embed-code/1560>\
**Category:** HubSpot Ideas\
**Tags:** integrations, forms\
**Created:** [April 10, 2017, 1:03pm UTC](https://community.hubspot.com/t/customize-default-field-values-for-form-embed-code/1560 "2017-04-10T13:03:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shay](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/shay/32/54226_2.png) [@Shay](https://community.hubspot.com/u/Shay)\
**Post date:** [April 10, 2017, 1:03pm UTC](https://community.hubspot.com/t/customize-default-field-values-for-form-embed-code/1560/1 "2017-04-10T13:03:27Z")

</div>

[Migrated from legacy feedback forum with 68 votes.](http://ideas.hubspot.com/forums/76407-general-hubspot-ideas/suggestions/5485929-customize-default-field-values-for-form-embed-code)

I have had several instances where the ability to set the default values for form fields would have saved me hours of integration time.

For example:

My client has 10 webinar pages each with its own unique thank you page. Our current form configuration (not-HubSpot integrated) redirects the user to the appropriate thank you page which contains the webinar requested for view.

I can already dynamically change the thank you page destination from the form embed code - but what I am looking for is to also set a hidden fields value inside the embed code as well.

For example the embed code would look something like this:

\<script\>  
hbspt.forms.create({  
portalId: ‘XXXXXX’,  
formId: ‘XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX’,  
formFields: {  
fieldID1 : {  
value : “my value”  
},  
fieldID2 : {  
value : “my value”  
}  
}  
});  
\</script\>

Where the field ID parameters and their values would correspond to certain fields (hidden or visible) in the form. This would allow me to use a single form across multiple pages on my site and also be able to send through the correct values for certain form fields based on the action / content they requested on the site.

If you guys can do this - or if it is already possible and I didn’t know about it - I would love you forever.

---

<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:** [March 22, 2019, 1:14pm UTC](https://community.hubspot.com/t/customize-default-field-values-for-form-embed-code/1560/2 "2019-03-22T13:14:22Z")

</div>

Hi all,

It is currently possible to [modify a HubSpot form’s embed code](https://developers.hubspot.com/docs/methods/forms/advanced_form_options) and [set field values with jQuery](https://developers.hubspot.com/manipulating-forms-with-jquery). This method applies to all fields, visible or hidden.

Here is an example form embed code which sets the value of the hidden `country` field to `wakanda`:

```auto
hbspt.forms.create({ 
 portalId: 'XXXXXX',
 formId: 'aa8b5b4a-62ac-461b-a387-XXXXXXXXXXX',
 onFormReady: function($form, ctx){
 	$('input[name="country"]').val('wakanda').change(); 
 	}
 });

```

(Remember to use the internal names of properties and their options.)

---

<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:** [March 22, 2019, 4:01pm UTC](https://community.hubspot.com/t/customize-default-field-values-for-form-embed-code/1560/3 "2019-03-22T16:01:21Z")

</div>

Empty

---

<div class="post-metadata">

**Author:** ![chrispower](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/chrispower/32/13521_2.png) [@chrispower](https://community.hubspot.com/u/chrispower)\
**Post date:** [February 7, 2020, 5:09am UTC](https://community.hubspot.com/t/customize-default-field-values-for-form-embed-code/1560/4 "2020-02-07T05:09:22Z")

</div>

This method of setting default values using the form embed code doesn’t appear to work for ‘Dropdown select’ fields. I’ve tested it successfully with a text field, but with drop down select, using the internal field name and the internal value, nothing happens on form load.

---

<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:** [February 12, 2020, 3:21pm UTC](https://community.hubspot.com/t/customize-default-field-values-for-form-embed-code/1560/5 "2020-02-12T15:21:19Z")

</div>

Hi, @chrispower.

Your use case is addressed in [this Community post](https://community.hubspot.com/t5/APIs-Integrations/How-to-select-from-a-dropdown-in-form-embed-code/m-p/231322).

Dropdown select fields are `select` elements rather than `input` elements, so you’ll have to modify your selector to be something like:

`$('select[name="dropdown"]').val('option1').change();`

Where `dropdown` is the _internal name_ of the dropdown property and `option1` is the _internal name_ of one of the property’s options.

If you have additional troubleshooting questions, please post them on either the “APIs & Integrations” or “CMS Development” boards [here](https://community.hubspot.com/t5/HubSpot-Developers/ct-p/developers).

---

<div class="post-metadata">

**Author:** ![EllieCookson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/elliecookson/32/29892_2.png) [@EllieCookson](https://community.hubspot.com/u/EllieCookson)\
**Post date:** [May 15, 2020, 3:30am UTC](https://community.hubspot.com/t/customize-default-field-values-for-form-embed-code/1560/6 "2020-05-15T03:30:47Z")

</div>

Hi @IsaacTakushi  
I was wondering if you could follow up on this - is there any way I can set a hidden fields value to contain a value that was filled out in the form previously?

For example, if someone put their **company name** as one of the answers to a question in the form, would you be able to make a hidden value of a website url incorporate that answer to be something like www.\<company name\>.com?

Thanks!

---

<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:** [May 15, 2020, 8:13pm UTC](https://community.hubspot.com/t/customize-default-field-values-for-form-embed-code/1560/7 "2020-05-15T20:13:04Z")

</div>

Hi, @EllieCookson.

Yes, this could be accomplished with some custom JavaScript which checks whether specific fields are filled [`onFormSubmit`](https://developers.hubspot.com/docs/methods/forms/advanced_form_options) and then copies the values to hidden fields.

With jQuery, this might look like:

```auto
hbspt.forms.create({
 portalId: 'XXXXXX',
 formId: 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
 onFormSubmit: function($form) {
 let companyName = $('input[name="company"]').val();
 if (companyName) {
	 $('input[name="custom_company_domain"]').val("www." + companyName + ".com").change();
	 }
 }
});

```

If your visitors are likely to submit company names with spaces, you’ll have to account for that with additional JavaScript.

I hope this helps! If you have follow-up questions, please post on the [APIs & Integrations](https://community.hubspot.com/t5/APIs-Integrations/bd-p/integrations) board.

---

<div class="post-metadata">

**Author:** ![CConant\_Raka](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@CConant\_Raka](https://community.hubspot.com/u/CConant_Raka)\
**Post date:** [October 20, 2023, 2:15pm UTC](https://community.hubspot.com/t/customize-default-field-values-for-form-embed-code/1560/8 "2023-10-20T14:15:58Z")

</div>

Thanks for the solution @IsaacTakushi! One thing to call out here is that you have to ‘Set as raw HTML form’ in the form’s ‘Style & preview’ settings for this to work.
