Created
December 23, 2017 18:58
-
-
Save bcls/dd8aad189a3d9c8c7599aa5a24160a18 to your computer and use it in GitHub Desktop.
Get Array of Checked checkbox Values #javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// collection of checkboxes obtained by getElementsByName() | |
/** | |
* get array of values for checked boxes in a collection | |
* @param {htmlElementCollection} checkBoxCollection collection of checkbox elements | |
* @return {Array} array of the values of the checked boxes | |
*/ | |
function getCheckedBoxValues(checkBoxCollection) { | |
var checkedValues = [], | |
i, | |
iMax; | |
if (checkBoxCollection) { | |
iMax = checkBoxCollection.length; | |
for (i = 0; i < iMax; i++) { | |
if (checkBoxCollection[i].check === true) { | |
checkedValues.push(checkBoxCollection[i].value); | |
} | |
} | |
return checkedValues; | |
} else { | |
console.log('Error: no input recieved'); | |
return null; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment