Processing Checkbox Group


/ Published in: HTML
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function checkBoxes(){
  2. var result, vals = [], checkBoxName = document.forms['formName']['checkBoxName[]'];
  3. for(var i=0,elm;elm = checkBoxName[i];i++) {
  4. if(elm.checked) {
  5. vals.push(encodeURIComponent(elm.value));
  6. }
  7. }
  8. result = vals.join(', ');
  9. }
  10. <form name="formName">
  11. <input type="checkbox" name="checkBoxName[]" value="Value 1" />
  12. <input type="checkbox" name="checkBoxName[]" value="Value 2" />
  13. <input type="checkbox" name="checkBoxName[]" value="Value 3" />
  14. <input type="checkbox" name="checkBoxName[]" value="Value 4" />
  15. <input type="checkbox" name="checkBoxName[]" value="Value 5" />
  16. <input type="button" onClick="checkBoxes()" />
  17. </form>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.