How to

Making WhatsApp Order Form using HTML, CSS, Javascript

Ravindra Kumar

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Order Form</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<script>
function sendOrderToWhatsApp() {
// Retrieve form values
var name = document.getElementById('name').value;
var email = document.getElementById('email').value;
var contact = document.getElementById('contact').value;
var address = document.getElementById('address').value;
var pincode = document.getElementById('pincode').value;
var landmark = document.getElementById('landmark').value;

// Retrieve product selections
var products = document.getElementsByName('product');
var orderDetails = '';
products.forEach(function(product) {
if (product.checked) {
var quantity = document.getElementById('quantity_' + product.value).value;
orderDetails += `Product: ${product.value}, Quantity: ${quantity}%0A`;
}
});

// Format the message
var formattedMessage = `Name: ${name}%0AEmail: ${email}%0AContact Number: ${contact}%0ADelivery Address: ${address}%0APincode: ${pincode}%0ALandmark: ${landmark}%0A%0AOrder Details:%0A${orderDetails}`;

// Your WhatsApp number (in international format, without '+' or '00')
var whatsappNumber = '919999999999'; // Replace with your number

// Create the WhatsApp URL
var whatsappURL = `https://wa.me/${whatsappNumber}?text=${formattedMessage}`;

// Open WhatsApp with the pre-filled message
window.open(whatsappURL, '_blank');
}
</script>
</head>
<body>
<div class="container m-5">
<h2>Place Your Order</h2>
<form onsubmit="sendOrderToWhatsApp(); return false;">
<div class="mb-3">
<label for="name" class="form-label">Name:</label>
<input type="text" class="form-control" id="name" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email:</label>
<input type="email" class="form-control" id="email" required>
</div>
<div class="mb-3">
<label for="contact" class="form-label">Contact Number:</label>
<input type="tel" class="form-control" id="contact" required>
</div>
<div class="mb-3">
<label for="address" class="form-label">Delivery Address:</label>
<textarea class="form-control" id="address" rows="2" required></textarea>
</div>
<div class="mb-3">
<label for="pincode" class="form-label">Pincode:</label>
<input type="text" class="form-control" id="pincode" required>
</div>
<div class="mb-3">
<label for="landmark" class="form-label">Landmark:</label>
<input type="text" class="form-control" id="landmark">
</div>
<div class="mb-3">
<label class="form-label">Select Products:</label><br>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="product1" name="product" value="Product1">
<label class="form-check-label" for="product1">Product 1</label>
<input type="number" class="form-control mt-1" id="quantity_Product1" placeholder="Quantity" min="1" value="1">
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="product2" name="product" value="Product2">
<label class="form-check-label" for="product2">Product 2</label>
<input type="number" class="form-control mt-1" id="quantity_Product2" placeholder="Quantity" min="1" value="1">
</div>
<!-- Add more products as needed -->
</div>
<button type="submit" class="btn btn-primary">Submit Order</button>
</form>
</div>

<!-- Bootstrap JS and dependencies (optional) -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/5.3.0/js/bootstrap.min.js"></script>
</body>
</html>

Explanation

  • Form Structure: The form includes fields for the user’s name, email, contact number, delivery address, pincode, and landmark.
  • Product Selection: Each product is represented by a checkbox (<input type="checkbox">) with an associated quantity input (<input type="number">). The quantity input is initially set to 1 and is linked to its corresponding product by appending the product value to the id attribute (e.g., id="quantity_Product1").
  • JavaScript Function: The sendOrderToWhatsApp() function retrieves the values from the form fields and constructs a formatted message string. It iterates over the product checkboxes to identify selected products and their quantities, appending this information to the order details. The message is then encoded and used to create a WhatsApp URL, which is opened in a new browser tab upon form submission.
  • Bootstrap Styling: Bootstrap classes such as form-control, form-check, and btn btn-primary are used to style the form elements, ensuring a responsive and user-friendly interface.

Whatsapp Form Code Generator Tool

Ravindra Kumar

Ravindra is a passionate full stack developer and dedicated blogger with a flair for crafting user-friendly web applications and insightful articles. With expertise spanning front-end and back-end technologies, Ravindra brings ideas to life through innovative coding solutions.

Suggested Reading

How to Create a WhatsApp Form on WordPress Using Ravindra Chat Form Plugin

WhatsApp has become the fastest way for customers to contact businesses online. Instead of waiting for emails or filling long contact forms, users prefer instant messaging. That’s why adding a WhatsApp form on your WordPress website is a smart move for lead generation and customer engagement. In this guide, you’ll learn how to create a […]

Whatsapp Contact Form Source Code Html CSS Javascript

<!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> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <style> body { background-color: #f8f9fa; } .contact-form { max-width: 600px; margin: 50px auto; padding: 20px; background: #fff; border-radius: 10px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); } </style> </head> <body> <div class="container"> <div class="contact-form"> <h2 class="text-center mb-4">Contact Us</h2> […]

How to submit HTML Form to WhatsApp | Sending Form fields to WhatsApp Using HTML,CSS and Javascript

Whatsapp Form Code Generator Tool In this post I am going to explain how can we submit HTML form to WhatsApp. By using this functionality form’s data will be summited to chat interface of WhatsApp, As normally we chat on WhatsApp. This example will tell you about sending form fields to WhatsApp by using JavaScript. […]

Making WhatsApp Order Form using HTML, CSS, Javascript

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Order Form</title> <!-- Bootstrap CSS --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous"> <script> function sendOrderToWhatsApp() { // Retrieve form values var name = document.getElementById('name').value; var email = document.getElementById('email').value; var contact = document.getElementById('contact').value; var address = document.getElementById('address').value; var pincode = document.getElementById('pincode').value; var landmark = document.getElementById('landmark').value; // Retrieve product selections var […]

Responsive Landing page source code in Html, CSS and Bootstrape

Landing pages are a critical element of any online marketing strategy. They are designed to capture leads, promote products, and convert visitors into customers. To create a compelling landing page, you don’t need to be an expert coder. With HTML, CSS, and Bootstrap, you can design a professional, responsive, and user-friendly landing page. In this […]

Download HTML Resume CV Template – Clean & Responsive Resume Template

Introduction Looking for a professional and easy-to-customize resume template? Our HTML Resume CV Template Download offers a clean, modern design perfect for showcasing your skills and experience online. Whether you’re a developer, designer, or any professional, this template helps create an impressive digital resume that stands out. About the HTML Resume CV Template Download This […]

Admin HTML Dashboard Download HTML CSS – Free Responsive Template

Introduction If you are looking to enhance your web application’s user interface, an admin HTML dashboard is a perfect solution. With the keyword “admin html dashboard download html css,” we focus on downloading a free, responsive, and customizable admin dashboard template built with HTML and CSS. This page will guide you through the features, benefits, […]

Download Free Real Estate HTML, CSS Template – Easy, Responsive & Professional

Introduction Looking for a clean, modern, and fully responsive real estate HTML and CSS template? You’re in the right place! This free real estate template is designed to help you showcase properties effectively and attract potential buyers or renters without the hassle of building your site from scratch. About the Download Free Real Estate HTML, […]