function checkForm var form document getElementById myForm var inputs

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
function checkForm () {
var form = document.getElementById('myForm');
var inputs = document.getElementsByTagName('input');
var flag = true;
for(var i = 0; i < inputs.length; i++){
if (inputs[i].value == '') {
alert(inputs[i].previousElementSibling.textContent);
inputs[i].style.borderColor = 'red';
flag = false;
} else {
inputs[i].style.borderColor = 'green';
}
}
if (flag) {
form.submit();
} else console.log('form no sub');
}