/ Published in: HTML
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<script> function checkBoxes(){ var result, vals = [], checkBoxName = document.forms['formName']['checkBoxName[]']; for(var i=0,elm;elm = checkBoxName[i];i++) { if(elm.checked) { vals.push(encodeURIComponent(elm.value)); } } result = vals.join(', '); } </script> <form name="formName"> <input type="checkbox" name="checkBoxName[]" value="Value 1" /> <input type="checkbox" name="checkBoxName[]" value="Value 2" /> <input type="checkbox" name="checkBoxName[]" value="Value 3" /> <input type="checkbox" name="checkBoxName[]" value="Value 4" /> <input type="checkbox" name="checkBoxName[]" value="Value 5" /> <input type="button" onClick="checkBoxes()" /> </form>