Wad JS
Wad JS
Wad JS
/project
├── index.html # HTML file for the webpage
├── styles.css # External CSS file
└── script.js # JavaScript file for dynamic styling
.dark-theme .header {
background-color: #1e1e1e;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interactive Form Example</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="form-container">
<h2>Sign-Up Form</h2>
<form id="signupForm">
<div class="form-group">
<label for="name">Name:</label>
<input type="text" id="name" placeholder="Enter your name" required>
<small class="error-message"></small>
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" id="email" placeholder="Enter your email" required>
<small class="error-message"></small>
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" id="password" placeholder="Enter a password" required>
<small class="error-message"></small>
</div>
<div class="form-group">
<label for="confirmPassword">Confirm Password:</label>
<input type="password" id="confirmPassword" placeholder="Confirm your password" required>
<small class="error-message"></small>
</div>
<script src="script.js"></script>
</body>
</html>
/* Form Container */
.form-container {
background-color: white;
padding: 30px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
width: 400px;
}
h2 {
text-align: center;
margin-bottom: 20px;
}
/* Form Group */
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input {
width: 100%;
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
margin-bottom: 5px;
}
input:focus {
border-color: #4CAF50;
outline: none;
}
/* Error Message */
.error-message {
color: red;
font-size: 0.875rem;
visibility: hidden;
}
/* Submit Button */
button {
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 1rem;
}
button:hover {
background-color: #45a049;
}
// Validate Name
if (nameInput.value.trim() === '') {
showError(nameInput, 'Name is required');
isValid = false;
}
// Validate Email
if (!validateEmail(emailInput.value)) {
showError(emailInput, 'Invalid email address');
isValid = false;
}
// Validate Password
if (passwordInput.value.length < 6) {
showError(passwordInput, 'Password must be at least 6 characters long');
isValid = false;
}