title: Show div based on select value
body: <p>I'm trying to make a form that changes after the users makes a choice. 
  If the user select "Option A" then show content of the div with the class "option1".</p>
  
  <p>I have already done this with very simple jquery(see code below or <a href="http://jsfiddle.net/bqexdk6s/4/" rel="nofollow">jsfiddle</a>).
  What I can't figure out is how to make it dynamic. </p>
  
  <p>Here is how I would do it in my head:</p>
  
  <ol>
  <li>Get all option values from "#select" and put into array.</li>
  <li>Replace the content of "hideAll" function with the new array.</li>
  <li>Make some kind of "for-each-function" that runs though the array and
  makes the if stament.</li>
  </ol>
  
  <p>A little note: The option value are always the same as the div class.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var hideAll = function() {
    $('.option1, .option2, .option3').hide();
  }
  
  $('#select').on('change', function() {
    hideAll();
    var category = $(this).val();
    console.log(category);
    if (category === 'option1') {
      $('.option1').show();
    }
    if (category === 'option2') {
      $('.option2').show();
    }
    if (category === 'option3') {
      $('.option3').show();
    }
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;form method="post"&gt;
    &lt;label for="option"&gt;Options&lt;/label&gt;
    &lt;select name="select" id="select"&gt;
      &lt;option value="option1"&gt;Option 1&lt;/option&gt;
      &lt;option value="option2"&gt;Option 2&lt;/option&gt;
      &lt;option value="option3"&gt;Option 3&lt;/option&gt;
    &lt;/select&gt;
  
    &lt;div class="option1" style="display:block;"&gt;
      &lt;label for="countries"&gt;Countries&lt;/label&gt;
      &lt;select name="countries"&gt;
        &lt;option value="denmark"&gt;Denmark&lt;/option&gt;
        &lt;option value="norway"&gt;Norway&lt;/option&gt;
        &lt;option value="uk"&gt;UK&lt;/option&gt;
      &lt;/select&gt;
    &lt;/div&gt;
  
    &lt;div class="option2" style="display:none;"&gt;
      &lt;label for="letters"&gt;Letters&lt;/label&gt;
      &lt;select name="letters"&gt;
        &lt;option value="a"&gt;A&lt;/option&gt;
        &lt;option value="b"&gt;B&lt;/option&gt;
        &lt;option value="c"&gt;C&lt;/option&gt;
      &lt;/select&gt;
    &lt;/div&gt;
  
    &lt;div class="option3" style="display:none;"&gt;
      &lt;label for="numbers"&gt;Numbers&lt;/label&gt;
      &lt;select name="numbers"&gt;
        &lt;option value="1"&gt;1&lt;/option&gt;
        &lt;option value="2"&gt;2&lt;/option&gt;
        &lt;option value="3"&gt;3&lt;/option&gt;
      &lt;/select&gt;
    &lt;/div&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>