Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Можно ли выполнить проход по всем input type = 'checkbox' (https://javascript.ru/forum/misc/26264-mozhno-li-vypolnit-prokhod-po-vsem-input-type-%3D-%27checkbox%27.html)

fortecul 02.03.2012 16:34

Можно ли выполнить проход по всем input type = 'checkbox'
 
В странице есть это:
<input type = ‘checkbox’ name = ‘rekviziti:1000:23:166:prl’>
<input type = ‘checkbox’ name = ‘rekviziti:1000:23:167:prl’>
<input type = ‘checkbox’ name = ‘rekviziti:1000:23:170:prl’>
<input type = ‘checkbox’ name = ‘rekviziti:1000:23:171:prl’>
<input type = ‘checkbox’ name = ‘rekviziti:1000:23:172:prl’>
<input type = ‘checkbox’ name = ‘rekviziti:1000:23:180:prl’>


Нужно что-то типа:

while ( пока_есть_инпуты_показать_значение_name_следующего ) {
ну и здесь значение
}

GuardCat 02.03.2012 16:40

Для современных браузеров:
var inputs = document.querySelectorAll("input[type=checkbox]");
for(var x = 0; x < inputs.length; x++) {
   console.log(inputs[x].name)
}

nikita.mmf 02.03.2012 17:49

var inputList = document.getElementsByTagName("input");
for ( var i = 0, input, checkboxName; ( input = inputList[i++] ) ; ) {
    if ( input.type == 'checkbox' ) {
        checkboxName = input.name;
    }
}


Часовой пояс GMT +3, время: 09:32.