[How to] Conditionally Display Additional Form Fields Based On Dropdown Selection



Show first post

142 replies

Badge

Hello ! 

I've just tested this script on my landing page, everything works perfectly, except that it's impossible to submit the form. When you click on the submit button, nothing happens... 
Could you help me? 

Thanks a lot, 
Perrine

I would like to do the same thing. Did you ever figure this out?

I’m also having an issue with this solution. Everything is working except upon submit of form, nothing happens. Any suggestions on what could be wrong?

Badge

Hi, I am looking for a similar functionality,

I need a form which when a checkbox is checked it shows an additional phone number field. Is there an existing script for this?

Userlevel 7
Badge +3

Hi @Perrine & @Timf

It might be a number of reasons… is the console throwing up any errors? 

Can you duplicate your pages on the unboucepages.com domain and share a link here so the community can try and troubleshoot it for you?


 

Hello everyone! I have a doubt on how to make this happen:

Basically, I want to:

  • When Dropdown = 0, no fields are shown and the submit button becomes just a link to a specific page.
  • If dropdown = 1 I ask for the email
  • If dropdown = 2, I ask for email and phone

Right now, the scripts I’m using are:

But this is not allowing me to show 2 fields (email and phone) when dropdown is 2.

Thanks

Badge

Hi @Hristian 

Thanks for your feedback. 

Here's the link to my test page with the form: http://unbouncepages.com/test-atawa/

Thanks for your help! 

Perrine

Hey @Carin Did you manage to do this? I’m looking for the same thing

@Hristian & @Perrine 

 

I figured it out… at least with my use case. I’m using dropdown selectors for conditionally displaying options. Apparently drop-down selectors appear as required by default if the option“first menu choice is not a valid value” is checked. This also applies to conditionally displayed dropdowns causing these fields to be required and causing form submission not to work. Since the form builder doesn’t have a required checkbox to enable/disable for dropdown selectors, I read on another thread to simply uncheck the option “first menu choice is not a valid value.” So apparently this change makes the dropdowns not required. The logic for this kind of makes sense but ideally I’d like to have the main dropdown required and still have instructional text as first option that is not selectable. 

I ended up doing something more “manual” and less pretty, but it works.

Hope somebody can answer my questions so I can make it better.

Badge

hello @Timf 

You're right, I've just tested without the "first menu choice is not a valid value" option and my form sends correctly! Like you, it's quite important for me to be able to keep this functionality. 
Do you think there is a solution @Hristian

Thanks :) 

Userlevel 7
Badge +3

Hi @Alfonsosbla,

You’ll need some custom JS and CSS to get the form working as you want.

The actual JS/CSS would have to be written specifically for your use case since you’ll have to adjust the position of the fields depending on your exact form. The JS would dictate the logic of what fields are shown when and based off of that the CSS would position the actual fields where they need to go.

On top of that you’ll have to play around with the fields validation and turn it on and off depending on what state the form is currently at. I posted a brief snippet above in regards to the validation.

Best,
Hristian

Hi Gary,
Did you ever figure this out?

Userlevel 7
Badge +3

Hi @Perrine

It should be possible to adjust the JS and “play” around with what’s required and what not at a particular state - if the field is visible or if it isn’t visible. 

I don’t have a ready made script but based on my experience with these Unbounce forms, it should be possible.  

Hello,

Thank you very much for the script. Im new here, I have no knowledge in doing jscript, I copied the script that was given but I cant seem to make it work with the below conditions, may I ask for help for the script on this one please:

  • When I select US, it should show City, State, Postcode fields.
  • Else, it hides city, state, postcode fields.

Thank you for the help!

Hi Rob,

I have implemented conditional form here on a lightbox "http://preference.lookyounger.net/look-younger/"

Now its not letting me submit the form, basically submit btn is not working :(.

Thanks

This. Is. Awesome! Love this basic form logic functionality, @Rob. 🙂

It’s possible to use it for more than 2 option?

Userlevel 7
Badge +1

You’re a ⭐ Rob!

We push to the limit! Thanks for support @Rob !

Just tried out this script today, really nice work! I too would be interested in having more than two fields if possible

This is great! Is it possible to have only the next field display (or not), but then have fields afterward that always display or does this only work when the fields are at the end of the form? I’m not much of a coder so any guidance or tips would be so appreciated! 🙂

Awesome got it working now, thanks so much for the help! @Rob

Userlevel 6

My pleasure 🙂

I’ve managed to add additional drop-down fields onto my landing page. However I’ve come across a bit of an obstacle. Your code allows there to be two different additional fields depending on the primary selection. I’m trying to make it work so that it allows nine different additional fields.

Testing this it seems to have worked (sort of). If my primary selection is number 3 or higher - the additional field that appears is positioned further down the page that it should be.

Is there any way you could help in fixing the code so that the position of any additional fields sits directly under the primary field (which happens with selection 1 or 2)?

Here is my preview page: https://app.unbounce.com/1189183/pages/06d025f0-3e4d-4af1-9718-d2d5380166bf/preview?variant_id=131744512#desktop

Thanks in advance!

Rajen

Reply