title: Showing JQuery selection depending on selection
body: <p>I have a page on my website that will show / hide fields on a form depending on what 
  
  <p><strong>HTML/PHP Code:</strong></p>
  
  <pre><code>&lt;select name="task_to_do" id="task_to_do" class="form-control" required&gt;
      &lt;option value="0"&gt;--- CHOOSE A TASK ---&lt;/option&gt;
      &lt;option value="1"&lt;?= $task['task_to_do'] == "1" ? " selected" : ""; ?&gt;&gt;-&gt; task 1&lt;/option&gt;
      &lt;option value="2"&lt;?= $task['task_to_do'] == "2" ? " selected" : ""; ?&gt;&gt;-&gt; task 2&lt;/option&gt;
      &lt;option value="3"&lt;?= $task['task_to_do'] == "3" ? " selected" : ""; ?&gt;&gt;-&gt; task 3&lt;/option&gt;                           
      &lt;option value="4"&lt;?= $task['task_to_do'] == "4" ? " selected" : ""; ?&gt;&gt;-&gt; task 4&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p><strong>JQuery:</strong></p>
  
  <pre><code>&lt;script&gt;
  $('#task_to_do').on('change',function() {
  
      // show public sites ...
      if (this.value == '1') {
          $("#register_public").show();
      } else {
          $("#register_public").hide();
      }
  
      // show private sites ...
      if (this.value == '2') {
          $("#register_private").show();
      } else {
          $("#register_private").hide();
      }
  
      // show login &amp; post ...
      if (this.value == '3') {
          $("#post").show();
      } else {
          $("#post").hide();
      }
  
      // show email ...
      if (this.value == '4') {
          $("#email").show();
      } else {
          $("#email").hide();
      }
  
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>This works well when the task is being created, the issue i have is when the task is being edited, i will allow the user to see their tasks and hit the edit button, when clicked, the user will see the form populated and what should happen is, depending on what <strong>task_to_do</strong> is selected, the jquery will show the relevant section, as it is now the user needs to re-select the section again before it shows, but it should be automatically shown on the page load, i'm not 100% with JQuery, any tips / or help would be appreciated.</p>