title: JavaScript Validation For Checkbox, When Multiple checkbox selected from option list
body: <p>I want to do JavaScript validation for Checkbox</p>
  
  <p>If Value from Checkbox is not selected, it should get alert "Please Select Languages You Know"</p>
  
  <p>But if user select 2 Languages from list of checkbox. I need that 2 languages should get alert using JavaScript.</p>
  
  <p>I know to do with single checkbox, but not getting how to do using array.</p>
  
  <p>Here is my Code...</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;script type="text/javascript"&gt;
   
  function myFunction(form){
      
    var i,
    chks = document.getElementsByName('lang[]');
    
    for (i = 0; i &lt; chks.length; i++){
      if (chks[i].checked){
          
        //Here how i should alert selected values 
          
          return true;
      }else{
          alert('No item selected');
          return false;
      }
    }
  }
  &lt;/script&gt;</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code> &lt;form name="registration" id="registration_form_id" action="" method="post" onsubmit="return myFunction(this)"&gt;
  
        &lt;div id="languageId"&gt;&lt;label&gt;Language : &lt;/label&gt;
                                                          
            &lt;input type="checkbox" name="lang[]" value="english" &gt;English&lt;/input&gt;
                                          
            &lt;input type="checkbox" name="lang[]" value="marathi"&gt;Marathi&lt;/input&gt;   
  
             &lt;input type="checkbox" name="lang[]" value="hindi"&gt;Hindi&lt;/input&gt; 
                                                      
        &lt;/div&gt;
  
       &lt;div id="submit1"&gt;&lt;button type="submit"&gt;Submit&lt;/button&gt;&lt;/div&gt;&lt;br/&gt;
  
       &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Thank You,
  Rahul</p>