<form id="myForm">
Имя:
<input type="text" name="name">
<input type="submit" value="Submit">
</form>
<script>
let form = document.getElementById('myForm');
form.addEventListener('submit', validateForm);
function validateForm(e) {
var x = form.elements.name.value;
if (x == null || x == "") {
form.elements.name.value = "Необходимо заполнить поле Имя!";
e.preventDefault();
}
}
</script>