<!
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form Example</title>
<style>
/* General body styling */
body {
font-family: 'Arial', sans-serif;
margin: 20px;
background-color: #f4f4f9;
color: #333;
}
/* Container to center the form */
.container {
max-width: 500px;
margin: 0 auto;
padding: 100px;
background-color: #ffffff;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
/* Header styling */
h2 {
text-align: center;
color: #333;
margin-bottom: 20px;
}
/* Styling the form elements */
form {
display: flex;
flex-direction: column;
}
label {
font-size: 20px;
margin-bottom: 10px;
color: #555;
}
input {
padding: 10px;
margin-bottom: 20px;
font-size: 16px;
border-radius: 4px;
border: 1px solid #ccc;
transition: border-color 0.3s;
</style>
<script>
function displayNames() {
var firstName = document.getElementById("first-name").value;
var lastName = document.getElementById("last-name").value;
var resultText = document.getElementById("result");
var errorText = document.getElementById("error");
// Clear any previous messages
resultText.innerText = '';
errorText.innerText = '';
// Check if both fields are filled
if (!firstName || !lastName) {
errorText.innerText = "Please fill in both fields!";
} else {
resultText.innerText = "Hello, " + firstName + " " + lastName + "!";
}
}
</script>
</head>
<body>
<div class="container">
<h2>Enter Your Name</h2>
<form>
<label for="first-name">First Name:</label>
<input type="text" id="first-name" name="first-name" required><br><br>
<label for="last-name">Last Name:</label>
<input type="text" id="last-name" name="last-name" required><br><br>
<button type="button" onclick="displayNames()">LOGIN</button>
</form>
<!-- Error message -->
<p id="error" class="error"></p>
<!-- p tag where the result will be displayed -->
<p id="result">Here is the result<br></p>
</div>
</body>
</html>