Experiment 6
Experiment 6
Source code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Form Validation</title>
<style>* {
box-sizing: border-box;
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f4f6f8;
.form-container {
width: 100%;
max-width: 400px;
background: #fff;
padding: 20px;
border-radius: 8px;
}
h2 {
text-align: center;
color: #333;
label {
display: block;
margin-top: 10px;
font-weight: bold;
color: #333;
input[type="text"],
input[type="number"],
select {
width: 100%;
padding: 8px;
margin-top: 5px;
border-radius: 4px;
font-size: 1rem;
.radio-group {
display: flex;
gap: 10px;
margin-top: 5px;
button[type="submit"] {
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
font-size: 1rem;
cursor: pointer;
margin-top: 15px;
button[type="submit"]:hover {
background-color: #45a049;
.error {
color: red;
font-size: 0.875rem;
</style>
</head>
<body>
<br><br>
<br><br>
<option value="CA">Canada</option>
</select>
<br><br>
<label>Gender:</label>
<label for="male">Male</label>
<label for="female">Female</label>
<label for="other">Other</label>
<br><br>
<button type="submit">Submit</button>
</form>
<script>function validateForm() {
let isValid = true;
// Username validation
isValid = false;
} else {
usernameError.textContent = "";
// Age validation
isValid = false;
} else {
ageError.textContent = "";
// Country validation
isValid = false;
} else {
countryError.textContent = "";
}
// Gender validation
if (!gender) {
isValid = false;
} else {
genderError.textContent = "";
}</script>
</body>
</html>
Output: