Make Calculator Results Shareable with URL State (No Backend Needed) A developer built a minimal, backend-free pattern for making calculator results shareable by storing form inputs in the URL query string. The approach writes state with history.replaceState on input changes and reads it back on page load, using a single field-description array that doubles as validation for min, max, and allowed values. Invalid or tampered query parameters are silently ignored, and the write-up notes that URLs leak into browser history, server logs, and analytics, so only non-sensitive inputs should be stored there. Disclosure: I used an AI assistant to help draft and edit this article. The code was written for illustration and tested by hand. Most small calculators lose everything on refresh. You type in an age, a time, a few counts, and the page gives you a score. Send the link to a friend and they see an empty form. The fix is cheap: store the inputs in the URL query string. No backend, no accounts, no local storage permissions. This post walks through a minimal pattern in plain JavaScript. I ran into this while working on a score lookup tool, aftptcalc.com https://aftptcalc.com/ , where people often want to send a result to a training partner. The same idea works for any form-driven calculator: mortgage, pace, unit converter, anything. The URL is the state. When inputs change, write them to the query string with history.replaceState . When the page loads, read the query string and fill the inputs. The calculation function only ever reads from the form, so it does not need to know about the URL. A single array describing the fields keeps the code short and avoids drift between reading and writing. js const FIELDS = { id: 'age', key: 'a', type: 'number', min: 17, max: 80 }, { id: 'sex', key: 's', type: 'select', allowed: 'm', 'f' }, { id: 'pushups', key: 'p', type: 'number', min: 0, max: 200 }, { id: 'runSeconds', key: 'r', type: 'number', min: 300, max: 3600 }, ; Short keys keep the URL tidy, and the min , max , and allowed values double as validation rules. js function writeState { const params = new URLSearchParams ; for const f of FIELDS { const el = document.getElementById f.id ; if el && el.value == '' params.set f.key, el.value ; } const qs = params.toString ; const url = qs ? ${location.pathname}?${qs} : location.pathname; history.replaceState null, '', url ; } I use replaceState , not pushState , so the Back button does not step through every keystroke. If you want each deliberate calculation to be a history entry, call pushState only when the user presses a Calculate button. Anything in a URL is user input, so never trust it. A shared link might be edited by hand or truncated by a chat app. js function readState { const params = new URLSearchParams location.search ; for const f of FIELDS { const raw = params.get f.key ; if raw === null continue; const el = document.getElementById f.id ; if el continue; if f.type === 'number' { const n = Number raw ; if Number.isFinite n && n = f.min && n <= f.max el.value = String n ; } else if f.type === 'select' { if f.allowed.includes raw el.value = raw; } } } Invalid values are silently ignored, so the form simply stays empty for that field. That is better than showing an error for a link someone else created. js document.addEventListener 'DOMContentLoaded', = { readState ; document.querySelectorAll 'input, select' .forEach el = { el.addEventListener 'input', = { writeState ; recalc ; } ; } ; recalc ; } ; recalc is your existing function that reads the form and prints a result. Notice that it is called once after readState , so a shared link shows the result immediately. js async function share { const url = location.href; if navigator.share { try { await navigator.share { title: document.title, url } ; return; } catch e {} } await navigator.clipboard.writeText url ; alert 'Link copied' ; } The Web Share API opens the native share sheet on phones. On desktop it is usually missing, so the clipboard fallback matters. Privacy. Anything in the URL ends up in browser history, server logs, and analytics tools. Only put non-sensitive inputs there. For a score calculator that is fine; for health records or finances, think twice. Time values. I store run time as seconds in the URL even if the form shows minutes and seconds. One number is easier to validate than two, and it avoids a format like 13:05 needing URL encoding. Defaults. Do not write a field to the URL if it is empty or equal to the default. Short URLs are friendlier. Static hosting. Because the query string never reaches your server logic, this works on any static host. Make sure your page does not redirect and strip the query string, which some trailing-slash rules do. Testing. The easiest test is a table of URLs and expected form values. Include a hand-edited bad value, a missing key, and a duplicated key. URLSearchParams.get returns the first duplicate, which is usually what you want. About forty lines of JavaScript turn a throwaway calculator into something people can bookmark, send, and come back to. If you have a different approach, such as encoding state in the hash or compressing it, I'd like to hear about it in the comments.