Как показать ошибки в форме проверки от объекта ошибки - PullRequest
0 голосов
/ 15 мая 2018

Как добавить текст в HTML, выбрав соответствующий тип объекта? Я пытаюсь выбрать одну ошибку из errorText и вставить ее в массив ошибок. И понятия не имею, как добавить в HTML.

        var btn = document.querySelector('.btn');
btn.addEventListener('click', checkForm);
var select = document.querySelector('.required');
var inputs = document.querySelectorAll('.form-element');
var errors = [];
var errorText = {
     1 : "The field 'First name' is empty",
     2:  "The field 'Last name' is empty",
     3:  "Pick your date of birth",
     4:  "Pick a country",
     5:  "The field 'E-mail' is empty",
     6:  "Enter your password",
     7:  "The field 'Address' is empty",
     8:  "Enter correct email",
     9:  "Current date is not allowed"
}

function checkForm() {
    for(i = 0; i < inputs.length; i++) {  
    if (inputs[i].value == "") {
        inputs[i].style.borderColor = 'red';
    }
}
   if(select.selectedIndex=="") {
    errors.push({el :4});
    select.appendChild(errors);
    // select.innerHTML = 'Please, select a country';
    return false;
   } else {
    return true;
   }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...