Form Validation
Validate a form before processing its values. Browser checks improve feedback, but a server must repeat validation for submitted data.
Where to run this
This example changes a document. Open it in the HTML playground, then select Run code. It runs inside a separate preview.
A practical example
<form id="booking">
<label for="name">Name</label>
<input id="name" required>
<button>Check</button>
</form>
<p id="result"></p>
<script>
document.getElementById("booking").addEventListener("submit", event => {
event.preventDefault();
document.getElementById("result").textContent = "Ready to review your booking.";
});
</script>
What happens
A missing required name blocks normal submission; a valid name shows the review message in a local browser project.