APIs & Integrations

swapnilmr
Member

How to change select option in HubSpot forms via a click event

I'm trying to change a form field in Hubspot form on a click event. Following is the JS for the same:

$("#BUTTON ID").on("click", function() {
$("#HUBSPOT FORM SELECT ID").val(1).change();
$('html, body').animate({
scrollTop: eval($("#SECTION ID").offset().top - 75)
}, 1000);
});

The scroll part is working fine, but the value is not being changed. Can anyone help me to solve this?

0 Upvotes
5 Replies 5
swapnilmr
Member

How to change select option in HubSpot forms via a click event

Thank you so much! It's working!

Derek_Gervais
HubSpot Alumni
HubSpot Alumni

How to change select option in HubSpot forms via a click event

Hi @swapnilmr,

Dropdown selects are a bit tricky, since you technically want to select the option in question and change its selected property. Try something like this:

$('select[name="test_dropdown_select"] > option[value="Desired Value"]').prop("selected", "selected").change();
kendrieling
Participant

How to change select option in HubSpot forms via a click event

How would you change this code to apply to a multi-select checkbox instead of a dropdown?

0 Upvotes
swapnilmr
Member

How to change select option in HubSpot forms via a click event

It's a dropdown select. It's on https://www.aujas.com/careers/experienced

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

How to change select option in HubSpot forms via a click event

Hi @swapnilmr,

Is the form field a radio select or a dropdown select? Are you sure your selector is targeting the input element? Can you give me a link to the page you're referring to?

0 Upvotes