[LRUG] Stumped: Dynamically showing and hiding a dropdown based on a previous dropdowns selection?

Jesse Waites jesse.waites at gmail.com
Mon Nov 21 07:41:27 PST 2016


Hi all,

I wanted to run this by you. I have a project wherein I have a dropdown
inside of a modal. Lets say it says "Users" and "Products". (It is more
complex and more than 2 options but this example gets the point across)

If the user selects "Users", I then need another dropdown to appear below
it that contains all of the users, so one can be selected. If the user
selects "Products", that dropdown is populated with all of the products.

In getting this started, I have the secondary dropdown in a div, lets call
it <div id="secondary">

If I open the console, I can hide and show it with $('#secondary).hide();
or $('#secondary').show();
but I can't seem to get it working inline, in a script tag, on the page. At
this point I'm not sure if I need to chase down an asset pipeline issue, or
perhaps it isn't working due to the fact it is inside a modal and not
immediately rendered. I'm kind of stumped and this is the first time I've
done something like this.

After I defeat this issue, I'll need to populate that dropdown, and I guess
I will use AJAX for that? Am open to any advice or input there as well.
I'll basically call Users.all or Products.all, but I don't want to hit the
database for that until the initial selection takes place... the user might
not select ANYTHING from that first dropdown and so would be wasteful to
make DB calls at that point.

Thank you very much for your time and advice,

-- 
Jesse Waites
Web Developer
JesseWaites.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20161121/474d88b3/attachment.html>


More information about the Chat mailing list