So I'm trying to make my form only show the "Read Terms" button after all of the required elements are filled. I came across this to get the required elements but now when I try to get the value of the elements they return undefined in the Chrome developer tools.
// Show Terms Button only if all required elements are filled.
let termsButton = document.getElementById("termsButton");
let allRequired = document.getElementById("contactForm").querySelectorAll("[required]");
const checkForRequiredDone = () =>{
if (allRequired.value != undefined && allRequired.value != "" && allRequired.value != null){
termsButton.style.display = "block";
}else{
termsButton.style.display = "none;"
}
}
Since I'm testing for not undefined, even if all of the required elements are filled the button is still showing.
Also this is on an onchange
attribute on the form element.
And also I do have jQuery but I thought this would be easier in JS...