001window.onload = ()=>
002{
003 const theFormElement = document.querySelector('form');
004 theFormElement.onsubmit = function()
005 {
006 for(let i = 0; i < theFormElement.elements.length; i++)
007 {
008 console.log("Element type: " + theFormElement.elements[i].type);
009 console.log("Element id: " + theFormElement.elements[i].id);
010 console.log("Element value: " + theFormElement.elements[i].value);
011 const labelElementText = theFormElement.elements[i].parentElement.firstElementChild.innerText;
012 console.log("Element label: " + labelElementText);
013 }
014
015 if(document.querySelector('input').value.length < 3)
016 {
017 event.preventDefault();
018 alert('username is too short');
019 }
020 }
021}