Form suggestions and calculated results
HTML Living Standard
Help people fill out a form by describing what a field expects, offering suggestions, or showing a calculated result.
On this page
Suggest values with autocomplete and datalist
The email autocomplete token tells the browser what kind of saved value may fit. The list attribute points to a datalist by its ID. Its options are suggestions, and the person can still type another value.
<form>
<p><label for="email">Email</label>
<input id="email" name="email" type="email" autocomplete="email"></p>
<p><label for="city">City</label>
<input id="city" name="city" list="cities"></p>
<datalist id="cities">
<option value="Yangon">
<option value="Mandalay">
</datalist>
</form>
What to expect Type in the City field to see suggestions in a browser that supports datalist. Try typing a different city.
Show a calculated value with output
The output element represents a calculation result. Its for attribute lists the IDs of the fields involved. JavaScript updates the result when the quantity changes.
How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Calculate a total</title>
</head>
<body>
<form id="order">
<label for="quantity">Quantity</label>
<input id="quantity" type="range" min="1" max="5" value="1">
<label for="total">Total</label>
<output id="total" for="quantity">$4</output>
</form>
<script>
const quantity = document.querySelector('#quantity');
const total = document.querySelector('#total');
quantity.addEventListener('input', () => {
total.value = '$' + quantity.valueAsNumber * 4;
});
</script>
</body>
</html>
What to expect Move the slider to its right edge. The total updates to $20.