for (i=1; i <= count; i++) {
num = documen.getElementById('id' + i). value;
alert(num);
}
Ошибка: Cannot read property 'value' of null.
Подскажите, где может быть косяк? Спасибо.
for (i=1; i <= count; i++) {
num = documen.getElementById('id' + i). value;
alert(num);
}
Цитата |
При помощи кнопки создается несколько полей text, где id |
<form>
<input type="text" value="1" id="id1" class="myinput" /><br/>
<input type="text" value="2" id="id2" class="myinput" /><br/>
<input type="text" value="3" id="id3" class="myinput" /><br/>
</form>
count = document.querySelectorAll(".myinput").length;
for (i=1; i <= count; i++) {
num = document.getElementById('id'+i).value;
alert(num);
}
objs = document.querySelectorAll(".myinput");
for (let obj of objs) {
num = obj.value;
alert(num);
}