Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a few different ways you could do this. The simplest is to have a few separate fieldsets, each one containing a single group of fields. Then, in jQuery, dependent on the select-menu's value you can show/hide these fieldsets, e.g.</p> <pre><code>&lt;fieldset id="f1"&gt; &lt;input name="something1" /&gt; &lt;input name="something2" /&gt; &lt;input name="something3" /&gt; &lt;/fieldset&gt; &lt;fieldset id="f2"&gt; &lt;input name="something4" /&gt; &lt;input name="something5" /&gt; &lt;input name="something6" /&gt; &lt;/fieldset&gt; &lt;select name="fieldset-choice"&gt; &lt;option value="f1"&gt;Fieldset 1&lt;/option&gt; &lt;option value="f2"&gt;Fieldset 2&lt;/option&gt; &lt;/select&gt; &lt;script type="text/javascript"&gt; jQuery('select[name=fieldset-choice]').change(function(){ var fieldsetName = $(this).val(); $('fieldset').hide().filter('#' + fieldsetName).show(); }); // We need to hide all fieldsets except the first: $('fieldset').hide().filter('#f1').show(); &lt;/script&gt; </code></pre> <p><strong>Note</strong>: For the above technique to be entirely unobtrusive you might want to dynamically build the select-menu with the names of all the different fieldsets. </p> <hr> <p>Alternatively you can prefix each fields name with a meaningful prefix, and then hide/show according to that attribute:</p> <pre><code>&lt;input name="group1-name1" /&gt; &lt;input name="group1-name2" /&gt; &lt;input name="group2-name3" /&gt; &lt;input name="group2-name4" /&gt; &lt;input name="group2-name5" /&gt; &lt;select name="field-choice"&gt; &lt;option value="group1"&gt;Group 1&lt;/option&gt; &lt;option value="group2"&gt;Group 2&lt;/option&gt; &lt;/select&gt; &lt;script type="text/javascript"&gt; jQuery('select[name=field-choice]').change(function(){ var groupName = $(this).val(); $('input').hide().filter('[name^=' + groupName + ']').show(); }); // We need to hide all fields except those of the first group: $('input').hide().filter('[name^=group1]').show(); &lt;/script&gt; </code></pre>
    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.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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