<div dir="ltr">When you say ‘modal’, I’m guessing you mean some kind of modal popover? And you’re using a library for this modal?<div><br></div><div>You also haven’t mentioned what the actual JS you’re trying to execute is. </div><div><br></div><div>I’d put money on it not being an asset pipeline issue. Rather: I think your JS is not being bound to anything, because the dropdown isn’t present until the modal is triggered. The DOM is ready, you bind an onchange element to the 0 dropdowns that are present, and then when your dropdown pops into the DOM, there are no events bound to it.</div><div><br></div><div>So, you have two options: one is you bind the change event when the modal comes into being - I don’t know how your library works, so can’t tell you the syntax for this, but it’ll be a callback that fires when the modal is loaded - then, the dropdown inside it will have events bound to it.</div><div><br></div><div>The other is to bind the change method to a larger context. Because of the way event bubbling works, jQuery lets you do something like this:</div><div><br></div><div>$(body).on(‘change’, ‘select.my-select-inside-modal’, function() {</div><div>  $(“#thing-to-hide”).hide();</div><div>});</div><div><br></div><div>…and that’ll work even if the select element with that class isn’t present when the binding is made - all that matters (in that example) is that <i>body</i> is there to have that bound to. More here: <a href="http://api.jquery.com/on/">http://api.jquery.com/on/</a> . The JS developer console will be your friend debugging this - if in doubt, spit out the number of objects it can see that match the query when you make the binding, using console.log, and that’ll give you some clues.</div><div><br></div><div>As for your second question, that’s another big question, but suffice to say: the first A in Ajax is <i>asynchronous</i>. You won’t be firing off any database queries until the user requests it. So: when the change is made, you fire off a request, the server does a query and returns some data - probably as JSON - you parse the JSON to make some <option> objects and, finally, append them into the select. Have a look at the documentation around <i>responds_to</i> in Rails.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 21, 2016 at 3:41 PM, Jesse Waites <span dir="ltr"><<a href="mailto:jesse.waites@gmail.com" target="_blank">jesse.waites@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi all,<div><br></div><div>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)</div><div><br></div><div>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.</div><div><br></div><div>In getting this started, I have the secondary dropdown in a div, lets call it <div id="secondary"></div><div><br></div><div>If I open the console, I can hide and show it with $('#secondary).hide(); or $('#secondary').show();</div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>Thank you very much for your time and advice,</div><span class="HOEnZb"><font color="#888888"><div><div><br></div>-- <br><div class="m_8888762367575111896gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div>Jesse Waites</div><div>Web Developer</div><div><a href="http://JesseWaites.com" target="_blank">JesseWaites.com</a></div></div></div></div></div></div></div></div>
</div></font></span></div>
<br>______________________________<wbr>_________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a><br>
Archives: <a href="http://lists.lrug.org/pipermail/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/<wbr>pipermail/chat-lrug.org</a><br>
Manage your subscription: <a href="http://lists.lrug.org/options.cgi/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/options.<wbr>cgi/chat-lrug.org</a><br>
List info: <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/<wbr>listinfo.cgi/chat-lrug.org</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Tom Armitage<br><a href="http://infovore.org" target="_blank">http://infovore.org</a><br>07813 060578</div>
</div>