How to pass dropdown information through onFormReady with jQuery in forms?

forms

#1

What I'm trying to do:
User is selecting Region > Country > State/Province. Then they click on Email button to generate the HubSpot form. What I'm trying to do is then pass along the country and state/province to the HubSpot form. I honestly have no idea HOW to hit the form but I also don't seem to be able to hit the HubSpot dropdown with a fake value.

So I have the following data that I'd love to pass to HubSpot onFormReady:

State Please select a state Alabama Alaska Arizona

The HubSpot form fields are: email, country, state (dependent on country), organization, comments.

Then in my form I have:
hbspt.forms.create({
portalId: "numbers",
formId: "lots-of-numbers",
onFormReady($form){
$('input[name="email"]', $form).val('test@test.com').change();
$('select[name="country"]', $form).val('.lanschool-country').change();
}
})

So I tested and the email is passing through with this fake value. So I tried testing with say 'Benin' for country and nothing is being passed, let alone trying to pull from the form that needs to be passed. I've tried the following as well:
$('select[name="country"]', $form).val('Benin').change(); - nothing happens
jQuery('select[name="country"]', $form).val('Benin').change(); - nothing happens
$('input[name="country"]', $form).val('Benin').change(); - nothing happens
$('option[name="country"]', $form).val('Benin').change(); - nothing happens
$('#country-lots-of-numbers', $form).val('Benin').change(); - nothing happens

Really wish the documentation had an example here because I can't hit the drop down with a fake value. I assumed $('select[name="country"]', $form).val('Benin').change(); would do the trick but no.

So I found that I wasn't really matching the values. But now that I have matched the values how do I connect them through? So for example I'm using:
$('select[name="country"]', $form).val('select#country-africa option:selected').change();

I'm assuming the first section is to grab the country that is present. Then the value should be pulling from my form in finding the select with the id of country-africa and look for the option that's been selected. It's not actually pulling data over. What gives?


#3

Hi @jakedub,

What do you mean that it's not pulling data over? Do you mean that it's not appearing correctly in HubSpot, or that the select field isn't updating correctly to the value you chose?