<!
DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8”>
<meta name=”viewport” content=”width=device-width, initial-
scale=1.0”>
<title>Contact Form</title>
<style>
Body {
Font-family: Arial, sans-serif;
Background-color: #f9f9f9;
Display: flex;
Justify-content: center;
Padding: 40px;
Form {
Background: #fff;
Padding: 20px;
Border-radius: 10px;
Box-shadow: 0 0 10px rgba(0,0,0,0.1);
Width: 350px;
Label {
Font-weight: bold;
Display: block;
Margin-top: 10px;
}
Input, textarea, select {
Width: 100%;
Padding: 8px;
Margin-top: 5px;
Border: 1px solid #ccc;
Border-radius: 5px;
.error {
Color: red;
Font-size: 12px;
Display: none;
.preview {
Background-color: #f1f1f1;
Padding: 10px;
Border-radius: 5px;
Margin-top: 15px;
Display: none;
.btn {
Background-color: #007BFF;
Color: white;
Padding: 10px;
Border: none;
Border-radius: 5px;
Cursor: pointer;
Margin-top: 15px;
Margin-right: 5px;
</style>
</head>
<body>
<form id=”contactForm” method=”POST” onsubmit=”return
validateForm()”>
<h2>Contact Us</h2>
<label>Name:</label>
<input type=”text” id=”name” name=”name”>
<p class=”error” id=”nameError”>Please enter your name</p>
<label>Email:</label>
<input type=”email” id=”email” name=”email”>
<p class=”error” id=”emailError”>Enter a valid email address</p>
<label>Phone Number:</label>
<input type=”text” id=”phone” name=”phone” maxlength=”10”>
<p class=”error” id=”phoneError”>Phone number must be 10
digits</p>
<label>Message:</label>
<textarea id=”message” name=”message”></textarea>
<p class=”error” id=”messageError”>Message cannot be empty</p>
<label>Preferred Contact Method:</label>
<input type=”radio” name=”contactMethod” value=”Email”> Email
<input type=”radio” name=”contactMethod” value=”Phone”> Phone
<input type=”radio” name=”contactMethod” value=”Both”> Both
<label>Inquiry Type:</label>
<select id=”inquiryType” name=”inquiryType”>
<option value=””>Select an option</option>
<option value=”General Inquiry”>General Inquiry</option>
<option value=”Support Request”>Support Request</option>
<option value=”Feedback”>Feedback</option>
</select>
<button type=”button” class=”btn”
onclick=”previewForm()”>Preview</button>
<button type=”submit” class=”btn”>Submit</button>
</form>
<div class=”preview” id=”previewBox”></div>
<script>
Function validateForm() {
Let valid = true;
[Link](‘.error’).forEach(e => [Link] =
‘none’);
If ([Link](‘name’).[Link]() === ‘’) {
[Link](‘nameError’).[Link] = ‘block’;
Valid = false;
Let email = [Link](‘email’).value;
If (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
[Link](‘emailError’).[Link] = ‘block’;
Valid = false;
Let phone = [Link](‘phone’).value;
If (!/^\d{10}$/.test(phone)) {
[Link](‘phoneError’).[Link] = ‘block’;
Valid = false;
If ([Link](‘message’).[Link]() === ‘’) {
[Link](‘messageError’).[Link] = ‘block’;
Valid = false;
Return valid;
Function previewForm() {
If (!validateForm()) return;
Let previewBox = [Link](‘previewBox’);
[Link] = `
<h3>Preview Your Submission</h3>
<p><b>Name:</b> $
{[Link](‘name’).value}</p>
<p><b>Email:</b> $
{[Link](‘email’).value}</p>
<p><b>Phone:</b> $
{[Link](‘phone’).value}</p>
<p><b>Message:</b> $
{[Link](‘message’).value}</p>
<p><b>Contact Method:</b> $
{[Link](‘input[name=”contactMethod”]:checked’)?.value
|| ‘Not Selected’}</p>
<p><b>Inquiry Type:</b> $
{[Link](‘inquiryType’).value || ‘Not Selected’}</p>
`;
[Link] = ‘block’;
</script>
</body>
</html>