Public Access
0
0
Files
blanks/js/DOM/checkbox.md

28 lines
869 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Обработка input checkbox
#### Получить массив выбранных чекбоксов
```js
/**
* @params str parent_id - ID элемента откуда начинается поиск input с типом checkbox
*
* @result arr - Массив выбранных checkbox`ов
*
*/
function getCheckedCheckBoxes(parent_id) {
if(parent_id == "") alert("Не указан ID родителя");
var checkboxes = document.getElementById(parent_id).querySelectorAll("input[type='checkbox']");
var checkboxesChecked = [];
for (var index = 0; index < checkboxes.length; index++) {
if (checkboxes[index].checked) {
checkboxesChecked.push(checkboxes[index].value);
}
}
return checkboxesChecked; // для использования в нужном месте
}
```