Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are plenty of solutions for that. One of the simpliest options is to change your markup a bit and use <code>div</code> IDs.</p> <p><em>HTML:</em></p> <pre><code>&lt;div id="section1"&gt; &lt;label for="food"&gt;What is your favourite type of food?&lt;/label&gt; &lt;select id="food" onchange="selection(this)"&gt; &lt;option value="pizza"&gt;Pizza&lt;/option&gt; &lt;option value="mex"&gt;Mexican&lt;/option&gt; &lt;option value="thai"&gt;Thai&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;div id="section_pizza" style="display: none;"&gt; What is your favourite type of pizza?&lt;br&gt; &lt;label for="hawaiian"&gt;Hawaiian&lt;/label&gt;&lt;input type="radio" id="hawaiian"&gt; &lt;label for="supreme"&gt;Supreme&lt;/label&gt;&lt;input type="radio" id="supreme"&gt; &lt;label for="vegetarian"&gt;Vegetarian&lt;/label&gt;&lt;input type="radio" id="vegetarian"&gt; &lt;/div&gt; </code></pre> <p><em>JavaScript:</em></p> <pre><code>function selection(select) { document.getElementById("section_" + select.value).style.display = "block"; } </code></pre> <hr> <p>However, you can use <a href="http://jquery.com/" rel="nofollow">JQuery library</a> and make it faster and more flexible. You can easily add animation to blocks and add extra functionality.</p> <p><em>HTML:</em></p> <pre><code>&lt;div id="section1"&gt; &lt;label for="food"&gt;What is your favourite type of food?&lt;/label&gt; &lt;select id="food"&gt; &lt;option value="pizza"&gt;Pizza&lt;/option&gt; &lt;option value="mex"&gt;Mexican&lt;/option&gt; &lt;option value="thai"&gt;Thai&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;div id="section2" data-type="pizza" style="display: none;"&gt; What is your favourite type of pizza?&lt;br&gt; &lt;label for="hawaiian"&gt;Hawaiian&lt;/label&gt;&lt;input type="radio" id="hawaiian"&gt; &lt;label for="supreme"&gt;Supreme&lt;/label&gt;&lt;input type="radio" id="supreme"&gt; &lt;label for="vegetarian"&gt;Vegetarian&lt;/label&gt;&lt;input type="radio" id="vegetarian"&gt; &lt;/div&gt; </code></pre> <p><em>JavaScript:</em></p> <pre><code>$("#food").change(function() { $("[data-type]").hide(); $("[data-type='" + this.value + "']").show(1000); }); </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.
 

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