Skip to main content

 Restaurant Reservation System(Mini Project) Using HTML,CSS and JavaScript

Project Title: Restaurant Reservation System

🔍 Description:

The Restaurant Reservation System is a web-based application designed to streamline the table booking process for restaurants. It enables customers to make reservations quickly and conveniently by filling out an online form with their personal details, preferred date, time, number of guests, and any special requests.

The system performs smart validation to ensure that users cannot book for past dates or time slots that have already passed, especially on the current day. Upon successful booking, a confirmation message is displayed to the user.


🛠️ Technologies Used:

  • HTML – for structuring the form elements and layout.

  • CSS (Internal) – for styling the form, layout, and confirmation box.

  • JavaScript (Internal) – for form validation, logic to block past bookings, and dynamic confirmation messages.


🎯 Features:

  • User-friendly form for table reservations.

  • Validation to prevent selection of past dates and times.

  • Responsive and clean design using only internal CSS.

  • Dynamic confirmation message with booking summary.

  • No backend required – runs entirely on the client side.


💡 Future Enhancements:

  • Integrate with a backend (Node.js, Flask, Firebase) to store reservations.

  • Send email or SMS confirmation to the user.

  • Add admin panel to manage, approve, or cancel bookings.

  • Include a calendar to show available time slots dynamically.

  • Responsive improvements for mobile/tablet devices.


Code:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>Restaurant Reservation</title>

  <style>
    body {
      font-family: 'Segoe UI', sans-serif;
      background: #f8f9fa;
      margin: 0;
      padding: 20px;
    }

    .reservation-container {
      max-width: 600px;
      margin: auto;
      background-color: white;
      padding: 25px;
      border-radius: 12px;
      box-shadow: 0 0 12px rgba(0,0,0,0.1);
    }

    h2 {
      text-align: center;
      margin-bottom: 20px;
      color: #333;
    }

    label {
      display: block;
      margin-top: 15px;
    }

    input, select, textarea {
      width: 100%;
      padding: 10px;
      margin-top: 6px;
      border-radius: 5px;
      border: 1px solid #ccc;
      box-sizing: border-box;
    }

    button {
      margin-top: 20px;
      width: 100%;
      padding: 12px;
      background-color: #28a745;
      color: white;
      font-size: 16px;
      border: none;
      border-radius: 6px;
      cursor: pointer;
    }

    button:hover {
      background-color: #218838;
    }

    .confirmation {
      margin-top: 20px;
      font-weight: bold;
      color: #155724;
      background-color: #d4edda;
      padding: 15px;
      border-radius: 8px;
      display: none;
    }

    .error {
      color: red;
      font-size: 14px;
      margin-top: 5px;
    }
  </style>
</head>
<body>
  <div class="reservation-container">
    <h2>Restaurant Reservation Form</h2>
    <form id="reservationForm">
      <label for="name">Full Name:</label>
      <input type="text" id="name" required>

      <label for="phone">Phone Number:</label>
      <input type="tel" id="phone" required pattern="[0-9]{10}" placeholder="10-digit number">

      <label for="date">Reservation Date:</label>
      <input type="date" id="date" required>

      <label for="time">Time:</label>
      <input type="time" id="time" required>

      <label for="guests">Number of Guests:</label>
      <input type="number" id="guests" min="1" max="20" required>

      <label for="requests">Special Requests (Optional):</label>
      <textarea id="requests" rows="3" placeholder="e.g. window seat, birthday celebration"></textarea>

      <div id="errorMsg" class="error"></div>

      <button type="submit">Reserve Now</button>
    </form>

    <div class="confirmation" id="confirmationMsg"></div>
  </div>

  <script>
    const form = document.getElementById("reservationForm");
    const dateInput = document.getElementById("date");
    const timeInput = document.getElementById("time");
    const errorMsg = document.getElementById("errorMsg");

    // Set minimum date to today
    const today = new Date().toISOString().split("T")[0];
    dateInput.setAttribute("min", today);

    form.addEventListener("submit", function (e) {
      e.preventDefault();

      const selectedDate = new Date(dateInput.value);
      const selectedTime = timeInput.value;

      const currentDate = new Date();
      const selectedDateTime = new Date(`${dateInput.value}T${selectedTime}`);

      // Clear error message
      errorMsg.textContent = "";

      // Prevent booking for past time today
      if (selectedDate.toDateString() === currentDate.toDateString()) {
        if (selectedDateTime <= currentDate) {
          errorMsg.textContent = "You cannot select a past time for today.";
          return;
        }
      }

      // Basic revalidation (just in case)
      if (selectedDateTime < currentDate) {
        errorMsg.textContent = "You cannot book for a past date or time.";
        return;
      }

      const name = document.getElementById("name").value.trim();
      const phone = document.getElementById("phone").value.trim();
      const guests = document.getElementById("guests").value;
      const requests = document.getElementById("requests").value.trim();

      const message = `
        Thank you, ${name}!<br>
        Your reservation for <strong>${guests}</strong> guest(s) on <strong>${dateInput.value}</strong> at <strong>${timeInput.value}</strong> has been confirmed.
        ${requests ? `<br><br>Special Requests: <em>${requests}</em>` : ""}
      `;

      document.getElementById("confirmationMsg").innerHTML = message;
      document.getElementById("confirmationMsg").style.display = "block";

      form.reset();
    });
  </script>
</body>
</html>



Comments

Popular posts from this blog

Navigating the Web: A Journey into the World of Web Development

 Introduction: In the age of the internet, web development stands as the architectural backbone that shapes our online experiences. It is the art and science of crafting the digital landscape we navigate daily, creating everything from informative blogs and interactive applications to e-commerce platforms and social media networks. At its core, web development involves the process of building, designing, and maintaining websites, transforming creative visions into functional and visually appealing online destinations. Developers, armed with a diverse set of skills, collaborate to bring websites to life, seamlessly blending aesthetics with functionality. Web development is a multifaceted discipline, encompassing both front-end and back-end development. Front-end developers focus on the user interface (UI) and user experience (UX), using languages like HTML, CSS, and JavaScript to ensure a website's visual appeal and interactivity. On the other hand, back-end developers delve into th...

Crafting User-Friendly Experiences: An Introduction to Responsive Web Design

  Introduction: Importance of Responsive Design:      Responsive design can help you solve a lot of problems for your website. It will make your site mobile-friendly, improve the way it looks on devices with both large and small screens, and increase the amount of time that visitors spend on your site. It can also help you improve your rankings in search engines. 1. User Experience (UX) Optimization:      Responsive Web Design (RWD) ensures a seamless and consistent user experience across diverse devices, from desktops to smartphones. Users can access and interact with content without disruptions, fostering a positive UX. 2. Mobile-First Approach:      Adopting a mobile-first strategy prioritizes design and functionality for mobile devices. This approach recognizes the increasing use of smartphones and ensures that the website is optimized for smaller screens. Designs are then progressively enhanced for larger screens. 3. Search Engine O...

Getting Started with CSS Frameworks: A Guide to Bootstrap

INTRODUCTON 1. Introduction to Popular CSS Frameworks: Bootstrap:      Widely embraced in the front-end development sphere, Bootstrap stands out with its responsive grid system, pre-styled components, and a rich set of utility classes. It streamlines development, ensuring a uniform user experience across diverse devices. Foundation:      Renowned for its mobile-first strategy and modular design, Foundation offers a flexible grid system and customizable UI components. Tailwind CSS:      Diverging from traditional frameworks, Tailwind CSS follows a utility-first approach. It provides low-level utility classes, allowing direct design implementation in your markup. 2. How to Use CSS Frameworks for Faster and More Consistent Development: Integration: Link the framework's stylesheet in your HTML file or utilize npm for installation. Import the required styles into your project. Grid System: Leverage the grid system for responsive layout design. Exa...