<!DOCTYPE html>
<html lang="en-US">
<body>
<p>Try to submit the empty form</p>
<form action="/user-name.php">
Name: <input type="text" name="name" oninvalid="myFunction()" required>
<button type="submit">Submit</button>
</form>
<script>
function myFunction(){
alert("Name field should not be empty");
}
</script> </body>
</html>