title: JS display:none/block via dropdown
body: <p>I have a form with one select field like this:</p>
  
  <pre><code>&lt;select onchange="toggle_form_element(this)" name="parts" id="parts"&gt;
      &lt;option value="-"&gt;Please choose&lt;/option&gt;
      &lt;option value="0"&gt;Part 1&lt;/option&gt;
      &lt;option value="1"&gt;Part 2&lt;/option&gt;
      &lt;option value="2"&gt;Part 3&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>Below this Form there are some div's, and I want do show / hide these div's based on the selected option in the dropdown field. Example:</p>
  
  <pre><code>&lt;div id="Form1"&gt;Part 1&lt;/div&gt;
  &lt;div id="Form2"&gt;Part 2&lt;/div&gt;
  &lt;div id="Form3"&gt;Part 3&lt;/div&gt;
  </code></pre>
  
  <p>My solution to get this working is the following js code: </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      function toggle_form_element(select) {
          if (select.value == '0') {
              document.getElementById('Form1').style.display = 'block';
              document.getElementById('Form2').style.display = 'none';
              document.getElementById('Form3').style.display = 'none';
          }else if (select.value == '1') {
              document.getElementById('Form1').style.display = 'none';
              document.getElementById('Form2').style.display = 'block';
              document.getElementById('Form3').style.display = 'none';
          }else if (select.value == '2') {
              document.getElementById('Form1').style.display = 'none';
              document.getElementById('Form2').style.display = 'none';
              document.getElementById('Form3').style.display = 'block';
          }else{
              document.getElementById('Form1').style.display = 'none';
              document.getElementById('Form2').style.display = 'none';
              document.getElementById('Form3').style.display = 'none';
          }
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>Now i would like to know if there is a way to make it shorter and simpler!? Because I have to add some more options to the select field.</p>