title: slect dropdown value, that checks checkbox and fills out input
body: <p><strong>Desired behavior:</strong></p>
  
  <p>1.Select "sweets" for <em>field1</em></p>
  
  <ol start="2">
  <li>the that will pre check values that have the same value as pre-selcted <em>field1</em></li>
  <li>if checkbox is checked it should trigger the input field to print out 
  strings that were checked
  ex. if value "a" is checked then is should display "a" in the input</li>
  <li>if "sweets" is checked in <em>field1</em> then <em>field3</em> will populate with value</li>
  </ol>
  
  <p>I have everything working except item 3. unless i check the items myself then they will display in the input. 
  I can not hard code any of the values in because the values will be dynamically brought in.</p>
  
  <p>Below i have a working example:</p>
  
  <p><a href="https://jsfiddle.net/kfb4nc03" rel="nofollow noreferrer">https://jsfiddle.net/kfb4nc03</a></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>document.getElementById('field1').onchange = function() {
    var boxes = document.querySelectorAll('input[type="checkbox"]');
    for (var i = 0; i &lt; boxes.length; i++) {
      boxes[i].checked = boxes[i].value == this.value;
  
      $checks = $(":checkbox");
      $checks.on('change', function() {
        var string = $checks.filter(":checked").map(function(i, v) {
          return this.value;
        }).get().join(" ,");
        $('#field_results').val(string);
      });
  
  
      document.getElementById("field3").value = this.value;
    }
  };</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;select name='field1' id="field1"&gt;
  
    &lt;option value="1"&gt;Fruits&lt;/option&gt;
    &lt;option value="2"&gt;Vegetables&lt;/option&gt;
    &lt;option value="3"&gt;Sweets&lt;/option&gt;
    &lt;option value="4"&gt;Meat&lt;/option&gt;
  &lt;/select&gt;
  
  
  &lt;div id='changer'&gt;
  
    &lt;input type='checkbox' id='a' value="3" /&gt;&lt;label&gt;A&lt;/label&gt;&lt;br /&gt;
    &lt;input type='checkbox' id='b' value="3" /&gt;&lt;label&gt;B&lt;/label&gt;&lt;br /&gt;
    &lt;input type='checkbox' id='c' value="3" /&gt;&lt;label&gt;C&lt;/label&gt;&lt;br /&gt;
    &lt;input type='checkbox' id='d' value="3" /&gt;&lt;label&gt;D&lt;/label&gt;
  &lt;/div&gt;
  
  &lt;input type="text" id="field_results" /&gt;&lt;br&gt;
  
  
  &lt;select name='field3' id="field3"&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;option value="4"&gt;4&lt;/option&gt;
  &lt;/select&gt;</code></pre>
  </div>
  </div>
  </p>