vendredi 12 mars 2021

Add Commas to checkbox array text Output

I used this Script to get array and its working nice. Just the Problem is, that i need "," between Values. Commas or new line.
Output now: ab
My Wish; a,b

Thanks for Help! :)

 $('.check').click(function() {
      $("#text").val('');
      $(".check").each(function() {
        if ($(this).prop('checked')) {

          $("#text").val($("#text").val() + $(this).val());
        }
      });
    });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" name="a" class="check" id="a" value="a"><label for="a"> a</label><br>
<input type="checkbox" name="b" class="check" id="b" value ="b"><label for="b"> b</label>
<br>
<input type="checkbox" name="c" class="check" id="c" value ="c"><label for="c"> c</label><br>
<input type="text" name="text" id="text">



Aucun commentaire:

Enregistrer un commentaire