Q:

validate if 1 to 3 chekboxes are cheked but with different id

I have a little problem here, so I have a form, inside I have 8 chekboxes in one section 
all are with images above them so if the user click over the image to check their specific chekboxes to .
Here is the code of my chekboxex and the script to validate them:

function logotype() {
  var group = document.newlogo.ltype;
  for (var i=0; i<group.length; i++) {
    if (group[i].checked)
      break;
  }
  if (i==group.length)
    return alert("Please select 1 to 3 Logo Types");
}
<div class="thumb1" >
  <label for="letter"><img class="img" src="images/my2.jpg"  /></label>
  <input type="checkbox" class="chk"   name="ltype[]"  id="letter" value="letter" />
  <hr>
  <p><strong>Letter Mark Logo</strong></p>
</div>
<div class="thumb1">
  <label for="emblerm"><img class="img" src="images/my3.jpg"  /></label>
  <input type="checkbox" class="chk"   name="ltype[]" id="emblerm" value="emblerm" />
  <hr>
  <p><strong>Emblerm Logo</strong></p>
</div>

As you may see the id="ltype" if i make all my checkboxes with the same id it works with validating but after this my checkboxes can't be checked from images because for="anothername" if i put ltype it makes all jujst select one field . .
So the question is: Can I somehow validate the checkboxes based on their class names so that at least 1 to three checkboxes are checked when submit?

A:

You can use getElementsByClassName() method to access the checkboxes using classname, and validate them as follows:
function logotype() {
  var failure = true,
  count =0,
  group = document.getElementsByClassName("chk");
  for (var i=0; i<group.length; i++) {
    if (group[i].checked)
      count++;
    if(count>=3){
      failure =false;
      break;
    }
  }
  if (failure){
     alert("Please select 1 to 3 Logo Types");
     return false;
  }
}

