Public Access
0
0

Добавить js/DOM/checkbox.md

This commit is contained in:
2026-03-11 17:36:04 +00:00
parent 4b0f03e9f5
commit d1ed6334f6

27
js/DOM/checkbox.md Normal file
View File

@@ -0,0 +1,27 @@
# Обработка 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; // для использования в нужном месте
}
```