0

Подскажите пожалуйста. есть функция CreateOL(number) которая создает упорядоченный список, где в каждый <li> вложен <input type="text"> Имеется массив <valspl> в котором лежат текстовые элементы Подразумевается, что пользователь вводит в input текст и потом нажав на кнопку checkall проверяет написанное с каждым элементом массива. ОДНАКО при проверке в функции checkTest() на второй итерации отладчик отображает, что value undefined (Uncaught TypeError: Cannot read property 'value' of undefined). Я пытался даже принудительно вписать значение в input input.value ='123' но все равно на второй итерации выбрасывает меня, говоря, что value undefined вот код

window.addEventListener("DOMContentLoaded", init);
function CreateOL(number){
    this.myOL = document.createElement("ol");
    this.myOL.style.marginTop = "10px";
    this.myOL.style.marginLeft = "30px";
    let right = document.querySelector("#right");
     for (let i=1; i<=number; i++) {
        this.myLI = document.createElement("li");
            this.myInput = document.createElement("input");
            this.myInput.type = 'text';
            this.myInput.name = 'answerfield';
            this.myInput.size = '50';
            this.myInput.value = '123';
            this.myInput.className = 'inputanswer';
            this.myInput.style.border = "1px solid black";
            this.myLI.appendChild(this.myInput);
            this.myOL.appendChild(this.myLI);       
        }
     right.appendChild(this.myOL);
     } 
 
 var newsplit = localStorage.getItem("val_split");
 var newsplit = localStorage.getItem("val_split");
 var finalval = localStorage.getItem("key_val");
 let valspl = finalval.split('\n');
 
CreateOL(newsplit);


function checkText() {
    for (let i = 0; i < newsplit; i++) {
        let checkline = this.myOL.childNodes[i].childNodes[i].value; /*обращение к значение input*/
        if (valspl[i] == checkline) {alert("Получилось!!!");}
        else {alert("Работать!");}
            
    }
}

function init() {
        let btncheckall = document.getElementById("checkall");
        btncheckall.addEventListener("click", function() {
            checkText();
        });
}
2

1 ответ 1

0
let checkline = this.myOL.childNodes[i].childNodes[0].value;
1
  • Вот же я разиня!!! Спасибо огромное
    – Дима
    20 июл 2020 в 6:10

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.