Populate a select drop down OR show input box based on selection in previous dynamically populated drop down

Greetings!  I have a form where wedding guests choose the wedding party from a drop down,  then based on their choice, another drop down will display OR an input box will display.  And the first drop down with the wedding parties is dynamically populated from an Access table.

There is only one wedding party with 4 choices of deposit amounts.  The guests of the other wedding parties will fill in what they need to pay that's why I only need an input box for them.

 Is this possible?  Thanks in advance.
meldraperAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
James BilousConnect With a Mentor Software EngineerCommented:
Oops, sorry, forgot a quote and a paren.

$("#amountSelect").change(function() {
   if ($("#amountSelect option:selected").attr("enumerated") !== undefined)
   {
      alert('enumerated');
   } 
   else
   {
      alert('input');
   }
});

Open in new window

0
 
James BilousSoftware EngineerCommented:
Yes, in your dropdown list of wedding parties, annotate the special one that requires the dropdown of amounts with a data parameter so that you can handle it differently in jquery. Something like:

<select id="amountSelect">
  <option value="party1">party1</option>
  <option value="party2" enumerated="true">party2</option>
  <option value="party3">party3</option>
  <option value="party4">party4</option>
</select>

Open in new window


$("#amountSelect").change(function() {
   if ($("#amountSelect option:selected).attr("enumerated") !== undefined
   {
      //Create your dropdown
   } 
   else
   {
      //Create your input
   }
});

Open in new window

0
 
meldraperAuthor Commented:
I love this.  I'll try it right now...
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
meldraperAuthor Commented:
James, I'm getting an error on this line and I don't know enough about JQuery to figure it out.

 if ($("#amountSelect option:selected).attr("enumerated") !== undefined
0
 
meldraperAuthor Commented:
This is just great!  how do i add my select and input box?
0
 
James BilousConnect With a Mentor Software EngineerCommented:
Check out this JS Fiddle, essentially you have the elements on the page already and show / hide them depending on the selection

https://jsfiddle.net/9jfg3mbu/
0
 
meldraperAuthor Commented:
Brilliant, thank you so much!!
1
 
zephyr_hex (Megan)DeveloperCommented:
Just want to note here that data attributes should be prefaced with the keyword "data".  An attribute called "enumerated" is not valid HTML.

The correct structure is:

<option value="party2" data-enumerated="true">party2</option>

Open in new window


And the correct way to access the attribute is:

if ($("#amountSelect option:selected").data("enumerated") !== undefined)

Open in new window

0
 
meldraperAuthor Commented:
Thank you!
0
 
meldraperAuthor Commented:
Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.