Google help on software/programming And Windows Tricks: Get all chekbox value and set into textbox as an array

helponsoftware

Friday 27 February 2015

Get all chekbox value and set into textbox as an array

<script>
$('input:checkbox').on('change',function () {
      if(this.checked){
       var Val = (this.checked ? $(this).val() : "");
       var oldVal = $('#idoftextbox').val();
      $('#idoftextbox').val(Val+","+oldVal);
  }
else{

     var Val = $(this).val();
     var oldVal = $('#idoftextbox').val();
     data = removeValue(oldVal,Val);
      $('#activity_level').val(data);
}

  });

function removeValue(list, value) {
  list = list.split(',');
  list.splice(list.indexOf(value), 1);
  return list.join(',');
}

</script>

No comments:

Post a Comment