Answer the question
In order to leave comments, you need to log in
How to show all errors in fields at once during form validation?
Good afternoon, I have a form with two fields.
Tell me, please, how to make it so that when you click on the button, all pop-ups for empty/incorrect fields are displayed at once? Now they are displayed one at a time (if both are empty, then only the first field will have a pop-up, and after filling in the first one, the second one, etc.), how to make them pop up all at once? Everything that I managed to google, using jquery and so on. And it is necessary on pure JS or without it.
Thank you!
<html lang="eng">
<head>
<title>Title</title>
<meta content="width=device-width, initial-scale=1" name="viewport" />
</head>
<body>
<form id="mainForm" action="#" method="POST">
<div>
<div>
<label for="first_name" title="first_name">First name<span class="mandatory">*</span></label>
<input id="first_name" name="first_name" type="text" value="" required=""
oninvalid="setCustomValidity('Enter first name')" oninput="setCustomValidity('')"
placeholder="Enter first name">
<p class="error_message"></p>
</div>
<div>
<label for="lastName" title="lastName">Last name<span class="mandatory">*</span></label>
<input id="lastName" name="lastName" type="text" value="" required=""
oninvalid="setCustomValidity('Enter last name')" oninput="setCustomValidity('')"
placeholder="Enter last name">
<p class="error_message"></p>
</div>
<div class="">
<input class="email_btn btn btn-block" type="submit" value="Submit">
</div>
</div>
</form>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
Tell me, please, how to make it so that when you click on the button, all pop-ups for empty/incorrect fields are displayed at once?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question