How to select from a dropdown in form embed code?

forms

#1

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?


#2

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?


#3

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