Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would try something along the lines of:</p> <pre><code>&lt;select name="milestone_tag" id="milestone_tag"&gt; &lt;option value="1" class="a"&gt;Selection A&lt;/option&gt; &lt;option value="2" class="b"&gt;Selection B&lt;/option&gt; &lt;option value="3" class="a-b"&gt;Selection C&lt;/option&gt; &lt;option value="4" class="a"&gt;Selection D&lt;/option&gt; &lt;/select&gt; &lt;div id="a" class="milestone"&gt; &lt;input name="milestone_a" value="milestone a" /&gt; &lt;/div&gt; &lt;div id="b" class="milestone"&gt; &lt;input name="milestone_b" value="milestone b" /&gt; &lt;/div&gt; &lt;div id="a-b" class="milestone"&gt; &lt;input name="milestone_a" value="milestone a" /&gt; &lt;input name="milestone_b" value="milestone b" /&gt; &lt;/div&gt; $(document).ready(function(){ var $milestones = $(".milestone"), $selector = $('#milestone_tag'); $selector.change(function() { var selected = $selector.find('option:selected').attr('class'); $milestones.hide(); $('#' + selected + '.milestone').show(); }); }); </code></pre> <p><a href="http://jsfiddle.net/userdude/ScWVZ/1/" rel="nofollow">http://jsfiddle.net/userdude/ScWVZ/1/</a></p> <p>A slightly more "complex" example that first tests and creates a local data value with the relevant <code>id</code> selectors, comma-separated, the is then used to display the related elements. Note the use of a (non-existent) <code>c</code>, and that <code>a</code> and <code>b</code> are not duplicate for the <code>a-b</code> case.</p> <p><a href="http://jsfiddle.net/userdude/ScWVZ/3/" rel="nofollow">http://jsfiddle.net/userdude/ScWVZ/3/</a></p>
 

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