SOLVED

Populate country in form field based on country selection in same form

Go to solution
Kiah_Kennedy
Level 1

Populate country in form field based on country selection in same form

I have a form that asks users to consent to their data being processed by a variable entity based on their country. I need to setup the form so that once a lead selects their country from the dropdown, the in the next field dynamically populates the entity with the country.

So for eg. I as a lead, go to this form. I select Canada as my country from the dropdown. Once I do that, the next field in the form dynamically autopopulates this text: "I consent to (company name) Canada to use my data"

I tried to accomplish this by using the lead country token within the form but it sometimes showed the default value even when country was filled out for a lead. Sometimes it worked.

Also important to note is that this is a guided landing page, and the dynamic content is contained within the form, not on the landing page.

Any help is appreciated!!

Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Populate country in form field based on country selection in same form

Exactly like so:

MktoForms2 :: VRs and templated output

Where the HTML of the output field's label is:

I consent to SpenceCo <output for="Country" name="brandedConsent"></output> using my data.

pastedImage_4.png

And the Visibilty Rule:

pastedImage_3.png

View solution in original post

8 REPLIES 8
Grégoire_Miche2
Level 10

Re: Populate country in form field based on country selection in same form

Hi Kiah,

Tokens will not help here. They could only be populated after the form is submitted to the database.

You will need some javascript to do this.

-Greg

Kiah_Kennedy
Level 1

Re: Populate country in form field based on country selection in same form

Hi Gregoire, thanks for your reply! What if we already have the lead country in our database? It worked a few times with tokens but other times it showed the default value even when we already had country populated for that lead in our database. Is this the behaviour you would expect? Thanks so much!!

Grégoire_Miche2
Level 10

Re: Populate country in form field based on country selection in same form

Hi Kiah,

Is the lead country is in the database, the token will populate, but I do not recommend you do this: if the person updates her country the token will not be updated.

The default value might be explained if you have duplicates in your database, or if the lead cannot be identified with the munchkin cookie.

-Greg

SanfordWhiteman
Level 10 - Community Moderator

Re: Populate country in form field based on country selection in same form

Exactly like so:

MktoForms2 :: VRs and templated output

Where the HTML of the output field's label is:

I consent to SpenceCo <output for="Country" name="brandedConsent"></output> using my data.

pastedImage_4.png

And the Visibilty Rule:

pastedImage_3.png

Grégoire_Miche2
Level 10

Re: Populate country in form field based on country selection in same form

Nice one

-Greg

Kiah_Kennedy
Level 1

Re: Populate country in form field based on country selection in same form

Hi Sanford, thank you so much for your response! I'm trying to figure this out, but I keep getting an empty value for country. Where do you suggest I place the JS? Do I need to put both the JS and HTML you provided in the code? Thanks again!

SanfordWhiteman
Level 10 - Community Moderator

Re: Populate country in form field based on country selection in same form

The HTML is in the Rich Text area.

The JS from the CodePen goes into a separate <script> tag.

  • If you're using a Marketo LP, put that <script> right above the closing </body> of your page.
  • If on a non-Marketo LP put the <script> anywhere after the standard form embed code.
Kiah_Kennedy
Level 1

Re: Populate country in form field based on country selection in same form

Got it. Thanks so much!!