You are viewing limited content. For full access, please sign in.

Question

Question

Dependent drop down values

asked on June 7, 2018

Hi All,

I'm new to Javascript and have been learning by reverse-engineering.  I'm having trouble with this one, however.  I have a simple form that has three drop downs.  I would like my form to auto-select values (from an existing list, not adding values to that list) in the second two drop downs based on the value selected in the first drop down. 

 

My drop downs are:

Ballot Type

Ballot Issue Method

Ballot Return Method

 

When the option "Polling" is selected in the Ballot Type drop down, I would like my form to automatically select the value "In Person" for both the Ballot Issue Method and Ballot Return Method drop downs.  These values are already options in these lists and don't need to be added.  When a different value is selected in the Ballot Type drop down, I don't want a value selected in the other two drop downs, they will be manually selected by the user.

 

How would you go about doing this?

 

Thanks!

1 0

Answer

SELECTED ANSWER
replied on June 7, 2018 Show version history

You'll want to go to the CSS and Javascript tab in the Forms Designer and place something like below code into the JavaScript section.

$(document).ready(function () {

 $('#q16').on("change", function(){
  if ($('#q16 select').val() == "Polling" ) {
   $('#q19 select').val("In Person").change();
   $('#q20 select').val("In Person").change();
  }
 }); //end change

}); // end doc ready

In the above example, q16 would represent the Ballot Type. When the value of that dropdown changes, the script evaluates whether the selected option has changed to "Polling". If yes, it sets the values of q19 and q20 to "In Person". To implement this, you should change the 16 to field number of Ballot Type, the 19 to the number of the Ballot Issue Method, and the 20 to the number of Ballot Return Method.

You may additionally want to make the Ballot Type and Ballot Issue Method say In Person and become read-only if the Ballot Type is Polling. Let me know if that's the case.

2 0
replied on June 7, 2018

Thanks so much for the code and the explanation, Karina! This was a huge help! I don't need the drop downs to become read only, but I'd love to see how that would look in your code if you have the time.

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.