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...
 πŸŒ Introduction to CSS: Styling the Web with Classes and Methods In the world of web development, HTML structures the content, but it's CSS (Cascading Style Sheets) that brings a website to life with design, layout, and visual aesthetics. Whether you're creating a personal portfolio or a professional website, CSS is essential for a visually appealing and user-friendly experience. In this blog, we’ll cover: What is CSS? Types of CSS CSS Syntax Classes in CSS Methods (or Techniques) in CSS Real-world Examples 🎨 What is CSS? CSS stands for Cascading Style Sheets . It’s a style sheet language used to describe the presentation of HTML documents . CSS defines how elements should be displayed—colors, fonts, layout, spacing, animations, and more. 🧠 Why Use CSS? Keeps design and content separate Reusability of styles across multiple pages Reduces code duplication Makes responsive web design possible πŸ—‚️ Types of CSS There are three types of CSS : ...