Show State/Province Field Only for US and Canada


#1

How can I use the unbounce forms in such a way to show the State/Province field only if someone is from US or Canada?
A second feature would be to show only the relevant States for US and Province for Canada


#2

Hey @aquamine! There isn’t a way to do this natively within the page builder. However, with some javascript, this could be possible. You could hide some elements based on IP addresses.

Our @Unbounce-Experts are more versed in javascript than I am (by leaps and bounds) so they may have more insight into this. But I might also see if folks from our tech team would be willing to provide some feedback here.

How comfortable are you with javascript? Let’s start there. :relaxed:


#3

Hey @aquamine, as Jess mentioned, this would involve some javascript.

I had a quick stab at it to help you out:

Here is a sample form in action
http://unbouncepages.com/test-form-143/

How to do this:

  • Create a form with the standard Unbounce “country” and “state/province” fields (located under the drop down form options in the form builder)

  • Add a “No State/Province” to the end of the state/province field options. The script will auto set the state/province to this when a country is not USA/Canada

  • Add this script to the Unbounce page, placed “Before Body End Tag”

Please note that this will simply hide/show the state field. When the field is hidden, there will be a blank space. If that is an issue, you can mess around with height/ positioning yourself to alter that.


Hope that helps!
Cheers
Brian


#4

Woot! This is awesome @Brian_Hemeryck!! Thanks for chiming in here. :raised_hands: :spinbounce: