APIs & Integrations

domel99
Participant

How to select from a dropdown in form embed code?

SOLVE

Hi. I can change the value of a simple text field using onFormReady in the form embed code, but can't figure out how to use the same code to select an option from a dropdown. Can anyone help?

This works for a text field:
hbspt.forms.create({
portalId: "xxxx",
formId: "xxxxx",
css: "",
onFormReady: function($form) {
$('input[name="firstname"]').val("Dave").change();

But this does not work for a dropdown:
hbspt.forms.create({
portalId: "xxxx",
formId: "xxxxx",
css: "",
onFormReady: function($form) {
$('input[name="dropdown"]').val("option1").change();

The field is definitely named correctly and the internal values match up with what I'm trying to select. Any ideas?

0 Upvotes
1 Accepted solution
domel99
Solution
Participant

How to select from a dropdown in form embed code?

SOLVE

Thanks for your reply, I solved it in the end. The extra step was to replace 'input' with 'select' in the final line.

View solution in original post

2 Replies 2
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

How to select from a dropdown in form embed code?

SOLVE

Hi @domel,

That same structure is working for me; are you sure that option1 is the internal name of the option, and not the option label?

0 Upvotes
domel99
Solution
Participant

How to select from a dropdown in form embed code?

SOLVE

Thanks for your reply, I solved it in the end. The extra step was to replace 'input' with 'select' in the final line.