how to take value only from the checked checkbox

function getCheckedValue(checkboxName) {
  var checkboxes = document.getElementsByName(checkboxName);
  var checkedValue = "";
  for (var i = 0; i < checkboxes.length; i++) {
    if (checkboxes[i].checked) {
      checkedValue = checkboxes[i].value;
      break;
    }
  }
  return checkedValue;
}