So I have a few text inputs on a form, and I'd like to make the borders glow red when the user tries to submit the form and the inputs do not meet a specific criteria. The criteria is that the fields cannot be empty, and if they are, the form will take the users back to the field and show a red border.
Below is what I've got so far, but not only do the styles not show up, but the fields disappear.
What do I need to change?
const submitButton = document.getElementById('submitButton');
const name = document.getElementById('name');
const email = document.getElementById('email');
function nameValidation() {
if (name.value == 0) {
name.style.borderColor = "red solid 5px";
}
}
function emailValidation() {
if (email.value == 0) {
email.style.borderColor = "red solid 5px";
}
}
submitButton.addEventListener('click', () => {
nameValidation();
emailValidation();
});
<form action="index.html" novalidate>
<fieldset>
<label for="name">Name:</label>
<input type="text" id="name">
<label for="mail">Email:</label>
<input type="email" id="email">
</fieldset>
<button id="submitButton">Register</button>
</form>