Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In my opinion, from the understanding on your question is that your desired function would look like this: <a href="http://jsfiddle.net/czAHJ/" rel="nofollow">http://jsfiddle.net/czAHJ/</a></p> <p>To explain things a bit more, take a look at the code...</p> <p>The HTML is simple, just the drop down and the results container:</p> <pre><code>&lt;select id="mySelect"&gt; &lt;option&gt;select&lt;/option&gt; &lt;option value="fruits"&gt; fruits&lt;/option&gt; &lt;option value="flowers"&gt; flowers&lt;/option&gt; &lt;/select&gt; &lt;div id="myResults"&gt;&lt;/div&gt; </code></pre> <p>Then the Javascript/jQuery code to add the functionality:</p> <pre><code>// wrap code in $(document).ready(), unless // you are certain that script is loaded after DOM $(document).ready(function () { var myFruits = ["apple","orange","banana"]; var myFlowers= ["rose","tulip","carnation"]; // use bind() as it's faster than click(), // also fire on 'change' instead $('#mySelect').bind('change', function () { // get value of the select to get our list // we dont need any jquery (bit faster) var list = false; if (this.value == 'fruits') { // use fruits list = myFruits; } else if (this.value == 'flowers') { // use flowers list = myFlowers; } else { // unknown, just ignore.. // lets clear the result container.. // or you can do something else: alert('Unknown Option'); $('#myResults').html(''); return false; } // require list if (list) { // collect html, use an array // its faster than concating to a string var html = []; // build html list from array (loop *could* be faster...) var len = list.length; for (var i = 0; i &lt; len; i++) { // add our string to the html array using .push html.push('&lt;li&gt;' + list[i] + '&lt;/li&gt;'); } // put our array of html back into a string // also, wrap it in a &lt;ul&gt; html = '&lt;ul&gt;' + html.join('') + '&lt;/ul&gt;'; // write html list to results, replacing old content $('#myResults').html(html); } }); }); </code></pre> <p>Let me know if this is the answer that you are looking for. I've tried to optimize the code as much as possible to keep things fast and light. (Best Practice)</p> <p>Cheers!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload