title: How to get checkbox value checked and show to input element using Javascript or Jquery?
body: <p>but the value is only displayed when I click on the checkbox and it does not display the pre-selected values, I want it to show the selected results even if I do not click the checkbox, please correct this code Help me or give me some example code so I can add, thank you!</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      function thayTheLoai() {
          var huunhan_theloai = [];
          $.each($("input[type='checkbox']:checked"), function() {
              huunhan_theloai.push($(this).val());
          });
          document.getElementById("input").value = huunhan_theloai.join(", ");
      }
  &lt;/script&gt;
  &lt;label for="default" onclick="thayTheLoai();" class="btn btn-default"&gt;
      &lt;input type="checkbox" value="1" id="theloai1" class="badgebox" name="theloai[]" &gt;&lt;/input&gt;
  &lt;/label&gt;
  &lt;input id="input" type="text"&gt;&lt;/input&gt;
  
  &lt;script&gt;
      $('#theloai1').prop('checked', true);
  &lt;/script&gt;
  </code></pre>
  
  <p>This is demo : <a href="https://anifast.com/includes/test.php" rel="nofollow noreferrer">https://anifast.com/includes/test.php</a>, I want to not need to click the checkbox and still display the checked results</p>