Hubspot form: programmatically set field value via jQuery

Occasional Contributor

Hi Community,

I am trying to programmatically set the value of a form field using jQuery, with the following code:


If I paste this code on Chrome console I see that the field changes, but then it gets updated with an empty value if I click on other fields.

The pages I am testing on are:

Donazione per il dispensario medico in Guatemala | MdB

Aiuta anche tu con un piccolo gesto per raccogliere fondi per il dispensario medico e le attività dell'ambulatorio nel Petén, in Guatemala

Code like the above used to work, as it is documented here

I have opened a ticket on HS, and support is checking if it is really a bug.

Has someone of you experienced this behavior recently?

Thank you very much in advance of your help.


34 Replies 34
New Member

Someone from this thread can look into this one Cannot read property 'target' of undefined from current.js please


I'm having exactly the same issue. I can successfully set the initial value of my fields but as soon as I click on and out of one of the fields all pre-set values get deleted again.


Does anyone have any news on this issue? I am using the code from the Documentation, although I added "$form" as second argument in the jQuery selector, because otherwise nothing would happen.


    portalId: 'XXXXXX',
    formId: 'aa8b5b4a-62ac-461b-a387-XXXXXXXXXXX',
    	$('input[name="firstname"]', $form).val('Brian').change();   

I am also having this issue.


@Derek_Gervais can you offer any advice?

Occasional Contributor

@Derek_Gervais I'm also having this problem and would really love some help with it.


My use case is leveraging the google maps API to provide autocomplete functionality for the address field. Everything works fine except for that the HS form code keeps clearing the autocompleted values. Tried every variation of jQuery we could think of, but HS keeps clearing the value.

HubSpot Moderator

Hey @Albo ,


As a general rule, it's better to create a brand new forum post than to post on an older one (>1 year old). Issues from greater than one year ago have usually been resolved, and aren't directly related to new/current issues.


That said, I'm happy to dive into whatever is going wrong here. Can you post a link to the page you're referring to so that I can take a closer look?