# Prepopulating form product codes?

**URL:** <https://community.hubspot.com/t/prepopulating-form-product-codes/19002>\
**Category:** CMS Development\
**Tags:** forms\
**Created:** [February 24, 2020, 4:25pm UTC](https://community.hubspot.com/t/prepopulating-form-product-codes/19002 "2020-02-24T16:25:39Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![PZee](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/pzee/32/59606_2.png) [@PZee](https://community.hubspot.com/u/PZee)\
**Post date:** [February 24, 2020, 4:25pm UTC](https://community.hubspot.com/t/prepopulating-form-product-codes/19002/1 "2020-02-24T16:25:39Z")

</div>

Hi,

I am trying to prepopulate a code for individual product posts using:

[https://developers.hubspot.com/manipulating-forms-with-jquery](https://developers.hubspot.com/manipulating-forms-with-jquery)

How does this work? Thanks.

---

<div class="post-metadata">

**Author:** ![alyssamwilie](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/alyssamwilie/32/2072_2.png) [@alyssamwilie](https://community.hubspot.com/u/alyssamwilie)\
**Post date:** [February 24, 2020, 10:17pm UTC](https://community.hubspot.com/t/prepopulating-form-product-codes/19002/2 "2020-02-24T22:17:07Z")

</div>

Hey @PZee ,

Use this code if you’re using a form widget instead of using the form embed by placing in the Footer HTML of either your template or your page settings.

```auto
$(window).load(function(){
 $('input[value="checkbox_1"]').prop('checked', true).change();
 $('input[name="firstname"]').val('Brian').change(); 
});

```

**$(window).load(function() {});** tells the browser to wait until the page has fully loaded, this way your script doesn’t try to run before the form is ready to be manipulated.  
**$(‘input[value=“checkbox\_1”]’)** and **$(‘input[name=“firstname”]’)** is where you tell the script which field you’re wanting to update. In a Hubspot form the field name is usually the internal property name that you would see in your properties listing or in the form editor in the field’s details.  
**.prop(‘checked’, true)** tells the script to set a checkbox or radio button to ‘true’, aka selected.  
**.val()** is where you tell a script what value you want a field to have. The text inside val( **‘Brian’** ) is what you would be changing the value to (the value is what is submitted to Hubspot). If you want to use a HubL value here you can like so **val(‘{{ hubl\_value\_name }}’)**  
**.change()** initiates the change of the value  
If you’re embedding your forms using Hubspot’s embed code you would use the onFormReady callback in your embed:

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

```

You can get the default embed code by going to your form dashboard and clicking the “Actions” button that shows up when you hover over the link to your form and selecting “Share form”. You’ll get a popup with the form embed.  
Then you’ll add the **onFormReady: function($form, ctx){** to tell the embed to wait to run the script until the form is ready to be manipulated.  
The rest inside the onFormReady callback is the same as for the other code.  
Hope this helps!

---

<div class="post-metadata">

**Author:** ![PZee](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/pzee/32/59606_2.png) [@PZee](https://community.hubspot.com/u/PZee)\
**Post date:** [February 28, 2020, 6:16pm UTC](https://community.hubspot.com/t/prepopulating-form-product-codes/19002/3 "2020-02-28T18:16:36Z")

</div>

Thank you for the reply!

I inputed this exactly, only with the correct Id’s. Did not use a widget for the form. On the top I put \<script\> and \</script\> on the bottom. Any suggestions on what I am still doing wrong?

```auto
hbspt.forms.create({
	portalId: 'XXXXXXX',
	formId: 'a60ed526-b2b4-49f9-b98c-XXXXXXXXXXXX',
 onFormReady: function($form, ctx){
 	$('input[value="product_code"]').prop('checked', true).change();
 	$('input[name="productcode"]').val('NFD-813').change();
});

```

---

<div class="post-metadata">

**Author:** ![alyssamwilie](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/alyssamwilie/32/2072_2.png) [@alyssamwilie](https://community.hubspot.com/u/alyssamwilie)\
**Post date:** [February 28, 2020, 6:18pm UTC](https://community.hubspot.com/t/prepopulating-form-product-codes/19002/4 "2020-02-28T18:18:25Z")

</div>

You’re missing a curly bracket

```auto
hbspt.forms.create({
	portalId: 'XXXXXXX',
	formId: 'a60ed526-b2b4-49f9-b98c-XXXXXXXXXXXX',
 onFormReady: function($form, ctx){
 	 $('input[value="product_code"]').prop('checked', true).change();
 	 $('input[name="productcode"]').val('NFD-813').change();
 }
});

```

---

<div class="post-metadata">

**Author:** ![PZee](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/pzee/32/59606_2.png) [@PZee](https://community.hubspot.com/u/PZee)\
**Post date:** [February 28, 2020, 6:29pm UTC](https://community.hubspot.com/t/prepopulating-form-product-codes/19002/5 "2020-02-28T18:29:10Z")

</div>

Thank you for the quick reply!

Tried it with the curly bracket but still no luck unfortunately. Any other ideas are greatly appreciated.

---

<div class="post-metadata">

**Author:** ![alyssamwilie](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/alyssamwilie/32/2072_2.png) [@alyssamwilie](https://community.hubspot.com/u/alyssamwilie)\
**Post date:** [February 28, 2020, 6:38pm UTC](https://community.hubspot.com/t/prepopulating-form-product-codes/19002/6 "2020-02-28T18:38:00Z")

</div>

What is the internal name of the form field you’re trying to update? And what type of field is it? You can find the internal name in the form editor and clicking on the field. It’ll be under “Contact property name”.

 ![formproperty.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/0/f/0f040513164cb7f7b8aed7e94ec63780ab7b7c2f.png)

---

<div class="post-metadata">

**Author:** ![PZee](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/pzee/32/59606_2.png) [@PZee](https://community.hubspot.com/u/PZee)\
**Post date:** [February 28, 2020, 6:47pm UTC](https://community.hubspot.com/t/prepopulating-form-product-codes/19002/7 "2020-02-28T18:47:06Z")

</div>

The name of the field is product\_code and it is a single-line text.

---

<div class="post-metadata">

**Author:** ![alyssamwilie](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/alyssamwilie/32/2072_2.png) [@alyssamwilie](https://community.hubspot.com/u/alyssamwilie)\
**Post date:** [February 28, 2020, 6:48pm UTC](https://community.hubspot.com/t/prepopulating-form-product-codes/19002/8 "2020-02-28T18:48:24Z")

</div>

```auto
hbspt.forms.create({
	portalId: 'XXXXXXX',
	formId: 'a60ed526-b2b4-49f9-b98c-XXXXXXXXXXXX',
 onFormReady: function($form, ctx){
 	 $('input[name="product_code"]').val('NFD-813').change();
 }
});

```

Try this

---

<div class="post-metadata">

**Author:** ![PZee](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/pzee/32/59606_2.png) [@PZee](https://community.hubspot.com/u/PZee)\
**Post date:** [February 28, 2020, 6:57pm UTC](https://community.hubspot.com/t/prepopulating-form-product-codes/19002/9 "2020-02-28T18:57:29Z")

</div>

Thank you for the reply!

Tried that and it still will not display the product code. Really appreciate the suggestions.

---

<div class="post-metadata">

**Author:** ![alyssamwilie](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/alyssamwilie/32/2072_2.png) [@alyssamwilie](https://community.hubspot.com/u/alyssamwilie)\
**Post date:** [February 28, 2020, 6:59pm UTC](https://community.hubspot.com/t/prepopulating-form-product-codes/19002/10 "2020-02-28T18:59:21Z")

</div>

Would it be possible for you to send me a preview link of the page you’re testing this form on?

---

<div class="post-metadata">

**Author:** ![PZee](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/pzee/32/59606_2.png) [@PZee](https://community.hubspot.com/u/PZee)\
**Post date:** [February 28, 2020, 7:02pm UTC](https://community.hubspot.com/t/prepopulating-form-product-codes/19002/11 "2020-02-28T19:02:00Z")

</div>

[http://www.neliasfloraldesign.com/easter-flower-basket/?preview\_id=6213&preview\_nonce=d79ad4951e&post\_format=standard&\_thumbnail\_id=3974&preview=true](http://www.neliasfloraldesign.com/easter-flower-basket/?preview_id=6213&preview_nonce=d79ad4951e&post_format=standard&_thumbnail_id=3974&preview=true) Here you go. Also just realized that it doubled the previous form.

---

<div class="post-metadata">

**Author:** ![alyssamwilie](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/alyssamwilie/32/2072_2.png) [@alyssamwilie](https://community.hubspot.com/u/alyssamwilie)\
**Post date:** [February 28, 2020, 7:21pm UTC](https://community.hubspot.com/t/prepopulating-form-product-codes/19002/12 "2020-02-28T19:21:39Z")

</div>

Couldn’t preview the link since it’s Wordpress and Wordpress only allows signed-in users to view previews.

However, from your live page I was able to see you’re using a **Free** Hubspot subscripton and, unfortanutely, manipulating forms isn’t available for such as noted in the [documentation](https://developers.hubspot.com/docs/methods/forms/advanced_form_options) :  
_Note: These options are only available for forms created using the marketing form builder available with a **paid** Basic, Professional, or Enterprise marketing subscription._

---

<div class="post-metadata">

**Author:** ![FMoksi33](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/fmoksi33/32/92090_2.png) [@FMoksi33](https://community.hubspot.com/u/FMoksi33)\
**Post date:** [February 7, 2021, 9:18pm UTC](https://community.hubspot.com/t/prepopulating-form-product-codes/19002/13 "2021-02-07T21:18:32Z")

</div>

Is there any improvement paintings going into adding Custom houses to Products? For example, each product has a SKU code this is a part of the deal that syncs to ERP [link](https://www.gearsireview.com/best-washer-and-dryer/). Is there any work going into being able to add a custom assets on a Product?
