Design a Survey Form Using HTML CSS and JavaScript

Coding has always fascinated me. The ability to create something functional and visually appealing from a blank canvas of code feels almost magical. Recently, I had the opportunity to work on a project that brought this magic to life the Survey Form Project using javaScript. This journey not only tested my skills but also taught me valuable lessons about patience, problem-solving, and the importance of user experience.

Vision Behind the Project

The idea was simple yet impactful: create a survey form that could be used for collecting user feedback. While it sounds straightforward, I wanted to go beyond the basics. My goal was to make the form:

  1. Visually Appealing – A user-friendly design that encourages engagement.
  2. Functional – Each element needed to work seamlessly.
  3. Responsive – Adaptable to different screen sizes and devices.

With these objectives in mind, I rolled up my sleeves and dived into the project.

Tools and Technologies Used

For this project, I relied on the following technologies:

  • HTML5: To structure the form with a clean and semantic layout.
  • CSS3: For styling and ensuring the design is visually engaging and responsive.
  • JavaScript: To add dynamic interactivity, including form validation and user feedback.
  • Google Fonts: To enhance the typography and overall user experience.
  • GitHub: To track progress, collaborate, and share the final project.

Coding Structure

Creating the basic structure involved using HTML5 elements to ensure accessibility and semantic correctness. Here’s how the form was built:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Survey Form</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <main>
        <h1>Feedback Survey</h1>
        <form id="survey-form">
            <fieldset>
                <legend>Personal Information</legend>
                <label for="name">Name:</label>
                <input type="text" id="name" name="name" placeholder="Your Name" required>

                <label for="email">Email:</label>
                <input type="email" id="email" name="email" placeholder="Your Email" required>

                <label for="age">Age:</label>
                <input type="number" id="age" name="age" min="10" max="100" placeholder="Your Age" required>
            </fieldset>

            <fieldset>
                <legend>Feedback</legend>
                <label>Rate Us:</label>
                <div>
                    <input type="radio" id="excellent" name="rating" value="excellent" required>
                    <label for="excellent">Excellent</label>

                    <input type="radio" id="good" name="rating" value="good">
                    <label for="good">Good</label>

                    <input type="radio" id="average" name="rating" value="average">
                    <label for="average">Average</label>
                </div>

                <label for="suggestions">Suggestions:</label>
                <textarea id="suggestions" name="suggestions" placeholder="Your feedback..."></textarea>
            </fieldset>

            <button type="submit">Submit</button>
        </form>
    </main>
    <script src="script.js"></script>
</body>
</html>

CSS Styling

To make the form visually appealing and user-friendly, I used modern CSS techniques. Here’s an overview of the styling choices:

  • Layout: Flexbox for centering and organizing elements.
  • Colors: A soothing palette to ensure a pleasant user experience.
  • Responsive Design: Media queries to adapt to various screen sizes.
body {
    font-family: 'Arial', sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-color: #f0f8ff;
}

main {
    width: 90%;
    max-width: 600px;
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

h1 {
    text-align: center;
    margin-bottom: 20px;
}

form {
    display: flex;
    flex-direction: column;
}

label {
    margin-top: 10px;
}

input, textarea, button {
    margin-top: 5px;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

button {
    background-color: #007bff;
    color: white;
    border: none;
    cursor: pointer;
}

button:hover {
    background-color: #0056b3;
}

JavaScript for Interactivity

Adding interactivity with JavaScript ensured the form was user-friendly. The script focused on:

  • Validating input fields to ensure users provided correct information.
  • Preventing form submission if required fields were empty.
  • Displaying feedback messages dynamically.
// Form validation
const form = document.getElementById('survey-form');

form.addEventListener('submit', function (event) {
    const name = document.getElementById('name').value;
    const email = document.getElementById('email').value;
    const age = document.getElementById('age').value;

    if (!name || !email || !age) {
        event.preventDefault();
        alert('Please fill out all required fields.');
    } else {
        alert('Thank you for your feedback!');
    }
});

Key Explanation

This project taught me how to integrate HTML, CSS, and JavaScript effectively. Here are the lessons I learned:

  1. Importance of Structure: Writing clean and semantic HTML makes the code maintainable and accessible.
  2. User-Centered Design: Styling and responsiveness are key to ensuring users enjoy interacting with your form.
  3. Interactive Elements: Adding JavaScript for validation and dynamic feedback enhances user experience.

Conclusion

The Survey Form Project has been a rewarding and enriching experience. It allowed me to combine creativity with technical skills to build a functional and user-friendly application. Through careful planning, attention to detail, and iterative problem-solving, I was able to create a form that not only works efficiently but also provides a pleasant user experience. This project has reinforced my passion for coding and motivated me to continue learning and creating meaningful projects. The journey from ideation to completion was filled with challenges, but each one provided an opportunity to grow and improve as a developer.

Related blog posts