Solved

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

Posted on 2016-10-27
10
27 Views
Last Modified: 2016-11-25
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.
0
Comment
Question by:meldraper
  • 6
  • 3
10 Comments
 
LVL 7

Expert Comment

by:James Bilous
Comment Utility
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
 

Author Comment

by:meldraper
Comment Utility
I love this.  I'll try it right now...
0
 

Author Comment

by:meldraper
Comment Utility
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
 
LVL 7

Accepted Solution

by:
James Bilous earned 500 total points
Comment Utility
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
 

Author Comment

by:meldraper
Comment Utility
This is just great!  how do i add my select and input box?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 7

Assisted Solution

by:James Bilous
James Bilous earned 500 total points
Comment Utility
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
 

Author Comment

by:meldraper
Comment Utility
Brilliant, thank you so much!!
1
 
LVL 42

Expert Comment

by:zephyr_hex
Comment Utility
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
 

Author Comment

by:meldraper
Comment Utility
Thank you!
0
 

Author Closing Comment

by:meldraper
Comment Utility
Thank you.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now