How to Build a Payment Receipt Generator in JavaScript (Free Source Code, 2026)
Build a free payment receipt generator in JavaScript — amount in words (lakh/crore), auto receipt numbers, saved history and print-ready PDF. Full tutorial + free source code.
Every time money changes hands in India — a client pays an advance, a customer settles a bill, a tenant pays rent — someone should get a receipt. Yet most small businesses and freelancers still rely on a WhatsApp message saying "payment received" or, worse, nothing at all. That habit costs real money: disputed payments, awkward follow-ups, and a paper trail that falls apart at tax time.
A payment receipt generator fixes all of that in under a minute. In this tutorial, you will build one yourself in plain HTML, CSS and JavaScript — no framework, no backend, no database. It creates professional receipts, converts the amount into words the Indian way (lakh and crore, not million and billion), numbers receipts automatically, saves a history, and prints a clean PDF. And if you would rather skip the build, you can download the finished, working version free from CodeFree at the end.
1. Why Every Payment Needs a Proper Receipt
A receipt is more than a courtesy. For a freelancer, it is proof of income that matches bank statements when a client later claims they "already paid". For a shop or service business, it is the document that settles arguments before they start. For anyone filing taxes, receipts are the difference between a clean books and a stressful scramble in March.
Indian businesses face one extra wrinkle: the amount in words. Banks, landlords and many clients still expect the amount written out — "Rupees Fifty Thousand Only" — and writing it by hand for every payment is slow and error-prone. A good generator does this automatically, in the Indian numbering system your payers actually use.
Before writing any code, decide what your receipt must contain:
- Your business details — name, phone, and optionally GSTIN.
- Payer details — who paid, and for what.
- Payment details — amount, date, payment mode (Cash, UPI, Bank Transfer, Cheque) and a reference number for digital payments.
- Amount in words — generated automatically in lakh/crore format.
- A unique receipt number — so no two receipts can ever be confused.
2. Step 1: Build the HTML Form and Receipt Layout
Start with a simple page split into two parts: a form on the left where you type the details, and a live receipt preview on the right that updates as you type. This instant feedback is what makes the tool feel professional instead of like a spreadsheet.
The form needs only a handful of fields: business name, payer name, amount, payment mode, date, and a short description of what the payment was for. Keep the field count low — every extra field is a reason for the user to abandon the tool. The receipt preview is a clean, bordered card styled like a real paper receipt: a header with your business name, a "PAYMENT RECEIPT" title, the receipt number and date, a table of details, the amount in big bold figures, the amount in words, and a signature line at the bottom.
<form id="receiptForm">
<input id="businessName" placeholder="Your business name">
<input id="payerName" placeholder="Received from">
<input id="amount" type="number" placeholder="Amount (₹)">
<select id="paymentMode">
<option>UPI</option>
<option>Cash</option>
<option>Bank Transfer</option>
<option>Cheque</option>
</select>
<input id="paymentDate" type="date">
<input id="purpose" placeholder="Payment for">
</form>
Wire every input to a single updatePreview() function with an input event listener. One function, one source of truth — the preview can never disagree with the form.
3. Step 2: Style It Like a Real Receipt (Including Print)
A receipt that looks great on screen but prints as a broken mess is useless. This is where most beginner projects fail, so get it right from the start.
Use a clean, print-friendly design: white background, dark text, a subtle border, and a coloured header band. Avoid heavy gradients and background images inside the receipt itself — printers often drop backgrounds, and a receipt with a missing background looks broken.
Then add a @media print block. This is the single most important piece of CSS in the whole project:
@media print {
body * { visibility: hidden; }
#receipt, #receipt * { visibility: visible; }
#receipt { position: absolute; top: 0; left: 0; width: 100%; }
}
This hides the form, buttons and page chrome, and prints only the receipt card. Add a "Print / Save as PDF" button that calls window.print(), and the browser's "Save as PDF" destination turns your receipt into a shareable PDF for free. Test the print output in Chrome at least once — a receipt that prints on two pages with the signature line orphaned on page two is a classic beginner bug. Keep the receipt under one A4 page by capping its height and font sizes.
4. Step 3: Convert Amounts to Words — the Indian Way
This is the heart of the project, and the part that makes it genuinely Indian. Western amount-to-words code says "One Million Five Hundred Thousand". Your users expect "Fifteen Lakh". The Indian numbering system groups digits differently after the first three: thousands, then lakhs (1,00,000), then crores (1,00,00,000).
The approach: write a function that handles numbers in two stages. First, a helper that converts any number from 0 to 99,999 into words using ones, tens and hundreds. Then a main function that splits the amount into crore, lakh, thousand and remainder parts and joins them:
function inWords(num) {
const ones = ["", "One", "Two", /* ... */ "Nineteen"];
const tens = ["", "", "Twenty", "Thirty", /* ... */ "Ninety"];
// handle 0–99, then hundreds
// then: crore = floor(num / 10000000)
// lakh = floor((num % 10000000) / 100000)
// thousand = floor((num % 100000) / 1000)
// remainder = num % 1000
}
Handle the paise too: split the amount on the decimal point, convert the paise part separately, and append "and Paise Fifty Only" when present. Always test with real Indian amounts — ₹1,50,000 should read "One Lakh Fifty Thousand", ₹1,00,00,000 should read "One Crore", and ₹12,500.50 should include the paise. Getting this function right is what separates a toy project from a tool a real shop can use.
5. Step 4: Auto Receipt Numbers and a Saved History
A receipt without a unique number is just a nicely formatted note. Generate numbers automatically in a clear format such as RCP-2026-0001, incrementing with every receipt. Store the counter in localStorage so it survives page reloads and never repeats a number.
While you are at it, save every completed receipt to a history list — also in localStorage. Each entry stores the receipt number, payer, amount, date and mode. Add a small history panel below the form with load and delete actions, so a shopkeeper can re-open last week's receipt in two clicks instead of retyping everything. This one feature turns a demo project into a daily-use tool.
Two details beginners often miss: validate before saving (block empty amounts and missing payer names with a clear inline error, not a silent failure), and escape user input when rendering it into the receipt — never inject raw text with innerHTML, or a payer name containing <script> becomes a security hole.
6. Step 5: Payment Modes That Change the Form
Not every payment needs the same fields. A cash payment needs no reference number; a UPI payment does (the UTR or transaction ID); a cheque needs a cheque number and bank name. Make the form adapt: when the user picks UPI, show a reference-number field; when they pick Cheque, show cheque number and bank fields; when they pick Cash, hide them both.
This is a small touch, but it is exactly the kind of detail that makes users trust a tool. It also keeps the printed receipt clean — a blank "Reference:" line on a cash receipt looks unfinished, while a filled UPI reference on a digital receipt looks thorough.
7. Common Mistakes Beginners Make
Skipping validation. A receipt with a blank amount or a negative number is worse than no receipt. Validate every field and show the error next to the field, not in a generic alert box.
Forgetting the print stylesheet. If you only test on screen, the first print will surprise you. Always test window.print() before calling the project done.
Using the Western number system. "One Million" on an Indian receipt confuses everyone. Lakh and crore are not optional — they are the requirement.
Hardcoding the business name. The tool should work for any business. Make the business name, phone and GSTIN editable fields, and remember them in localStorage so the owner types them once.
No history. A generator that forgets every receipt the moment you close the tab is a demo, not a tool. History is what makes people come back.
Frequently Asked Questions
Do I need a backend or database to build a receipt generator?
No. Everything in this project — the form, the amount-in-words conversion, receipt numbering, history and printing — runs entirely in the browser with plain JavaScript and localStorage. You can host it as a single static page on any hosting, including free static hosting.
How do I handle amounts in words for large values like crores?
Split the number into crore, lakh, thousand and remainder parts before converting each part to words, then join them with the right labels. Test with ₹1,00,00,000 (One Crore) and ₹1,50,00,000 (One Crore Fifty Lakh) — if those two come out right, your grouping logic is correct.
Can I save receipts as PDF instead of printing them?
Yes. The print stylesheet in Step 2 makes the browser print only the receipt. In the print dialog, choose "Save as PDF" as the destination instead of a printer, and you get a clean, shareable PDF with no extra software needed.
Is the finished version really free to download?
Yes. The complete, working Payment Receipt Generator — with amount in words, auto receipt numbers, receipt history, UPI/cheque/cash modes and print-ready PDF output — is available as a free download from CodeFree. Grab it below and use it in your own business or as a starting point for your own version.
Ready to use it instead of building it? Download the free Payment Receipt Generator from CodeFree — amount in words, auto receipt numbers, saved history and print-ready PDF, all included. Free source code, no sign-up needed.
Keep reading
How to Build an Image Resizer in JavaScript: Canvas API Tutorial (Free Source Code)
Build your own image resizer in JavaScript with the Canvas API — aspect-ratio lock, quality control, format conversion and watermarking, step by step with free source code.
Read article
How to Build a Color Palette Generator in JavaScript: Harmony Modes, Lock & CSS Export (Free Source Code)
Build a colour palette generator in JavaScript with harmony modes, locked colours, copy-to-clipboard and CSS export — step-by-step tutorial with free source code.
Read article
How to Build a Recipe App in JavaScript: Save, Search & Scale Servings (Free Source Code)
Build a working recipe app in plain HTML, CSS & JavaScript — add recipes, live search, a servings scaler, cook mode, and localStorage saving. No framework, no backend, just three files.
Read article