Take a look at this fiddle…the purpose of the code there is to style the inputs that the user did not check…on submit(you do not see any submit there,that role is resembled by the “style” div)…so clicking “style” the inputs that are not checked are styled.
Question:is there any shorter/cleaner alternative to this code?I think much code is there to do a simple task.
and use the click event on the submit button, to add a submitted class to each fieldset:
function formSubmitHandler(evt) {
var fieldsets = form.querySelectorAll("fieldset");
fieldsets.forEach(function(fieldset) {
fieldset.classList.add("submitted");
});
}
var form = document.querySelector("#myForm");
var submitButton = form.querySelector("[name='submit']")
submitButton.addEventListener("click", formSubmitHandler);
which you can use to then make invalid fields visible.