-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidation.html
More file actions
30 lines (28 loc) · 942 Bytes
/
validation.html
File metadata and controls
30 lines (28 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Form Validation</title>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("myForm").onsubmit = function(event) {
if (!document.getElementById("name").value || !document.getElementById("email").value) {
alert("All fields are required.");
event.preventDefault();
}
};
});
</script>
</head>
<body>
<h2>Simple Form Validation</h2>
<form id="myForm">
<label>Name:</label>
<input type="text" id="name"><br><br>
<label>Email:</label>
<input type="text" id="email"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>