# Set form field value with Jquery not working

**URL:** <https://community.hubspot.com/t/set-form-field-value-with-jquery-not-working/14884>\
**Category:** Lead Capture Tools\
**Tags:** forms\
**Created:** [June 20, 2019, 10:56am UTC](https://community.hubspot.com/t/set-form-field-value-with-jquery-not-working/14884 "2019-06-20T10:56:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jice-Lavocat](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jice-lavocat/32/2122_2.png) [@Jice-Lavocat](https://community.hubspot.com/u/Jice-Lavocat)\
**Post date:** [June 20, 2019, 10:56am UTC](https://community.hubspot.com/t/set-form-field-value-with-jquery-not-working/14884/1 "2019-06-20T10:56:37Z")

</div>

Hi there,

I’m trying to prepopulate a field on a HS form with JQuery (everything lives on a Vue app).

I have [read a topic](https://integrate.hubspot.com/t/passing-custom-form-data-to-a-hubspot-form-in-hidden-field/8861/2) that explicitely says that the value change should be chained with a “.change()” method.  
I’ve done that and, for debug puposes, I’m pre-populating the form on “hsFormCallback[onFormReady]” event. So that when I launch the page, the field is populated with my value. So far so good. Here is the code I’m using :

```auto
var score_global = $("input[name='score_global']");

score_global.val(123).trigger('change');

```

However, when I enter some text, in any other field available on the form, the prepopulated value disappears. It seems as if the _hsforms_ script doesn’t refresh with the trigger(‘change’) (it does the same if I use .change() instead).

Can anyone guide me here, I don’t know what to attempt now?

---

<div class="post-metadata">

**Author:** ![Derek\_Gervais](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/derek_gervais/32/17429_2.png) [@Derek\_Gervais](https://community.hubspot.com/u/Derek_Gervais)\
**Post date:** [July 1, 2019, 6:57pm UTC](https://community.hubspot.com/t/set-form-field-value-with-jquery-not-working/14884/2 "2019-07-01T18:57:43Z")

</div>

Hey @Jice-Lavocat ,

I’m having trouble replicating this behavior in my own account. Can you give me a link to the page in question so that I can take a closer look?

---

<div class="post-metadata">

**Author:** ![Jice-Lavocat](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jice-lavocat/32/2122_2.png) [@Jice-Lavocat](https://community.hubspot.com/u/Jice-Lavocat)\
**Post date:** [July 2, 2019, 7:24am UTC](https://community.hubspot.com/t/set-form-field-value-with-jquery-not-working/14884/3 "2019-07-02T07:24:55Z")

</div>

Hi [@Derek\_Gervais](https://community.hubspot.com/t5/user/viewprofilepage/user-id/142) ,

I eventually managed to fix the problem. The issue originates from a depency issue on JQuery for the hubspot form.js script.

To fix that in my Vue.Js app, I had to add the following lines.

```auto
// Needed by Vue.JS for using Jquery inside the app
import JQuery from 'jquery'
let $ = JQuery

// Needed by Hubspot Form.js
window.jQuery = window.jQuery || JQuery

```

---

<div class="post-metadata">

**Author:** ![Derek\_Gervais](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/derek_gervais/32/17429_2.png) [@Derek\_Gervais](https://community.hubspot.com/u/Derek_Gervais)\
**Post date:** [July 2, 2019, 2:56pm UTC](https://community.hubspot.com/t/set-form-field-value-with-jquery-not-working/14884/4 "2019-07-02T14:56:24Z")

</div>

That’s awesome, thanks for posting your solution here!

---

<div class="post-metadata">

**Author:** ![btfrost](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/btfrost/32/9373_2.png) [@btfrost](https://community.hubspot.com/u/btfrost)\
**Post date:** [October 20, 2020, 12:20pm UTC](https://community.hubspot.com/t/set-form-field-value-with-jquery-not-working/14884/5 "2020-10-20T12:20:49Z")

</div>

If anyone’s interested in solving this without jquery…

input.value = value;

input.dispatchEvent(new Event(‘input’, { bubbles: true }));

---

<div class="post-metadata">

**Author:** ![PamCotton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/pamcotton/32/47916_2.png) [@PamCotton](https://community.hubspot.com/u/PamCotton)\
**Post date:** [October 20, 2020, 8:26pm UTC](https://community.hubspot.com/t/set-form-field-value-with-jquery-not-working/14884/6 "2020-10-20T20:26:23Z")

</div>

Hey @btfrost thank you for sharing!

Pam
