jQuery Tutorial: Detect Input Value Changes with input and change
Use jQuery .on('input', handler) for updates while a user edits a value, and .on('change', handler) for updates when the change is committed. Checkboxes and radio buttons can use change to report selections. The demo compares these timings by multiplying two numbers.
Choose between input and change
input fires when the user changes the value, including by typing, deleting, or pasting. It tracks edits that do not rely on releasing a key. change fires when the edit is committed. For a number typed using the keyboard, that often occurs when the edited field loses focus. The HTML input event rules explain how this varies by input type.
| Goal | Event | When to update |
|---|---|---|
| Calculate while a number is edited | input |
Whenever the user changes the value |
| Calculate after a number is committed | change |
When the edit is committed |
| Read a checkbox or radio button | change |
When the checkbox changes or another radio is selected |
Binding both events to one operation can run it twice for the same edit. The demo connects them to separate outputs for comparison. See the jQuery .on() documentation for registration and the jQuery change event documentation for commit behavior.
Compare live and committed number changes
Save the complete document as jquery-input-change.html in UTF-8 and open it in a browser. It needs an internet connection to load jQuery 4.1.0 from the official CDN.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Detect input changes with jQuery</title>
<script src="https://code.jquery.com/jquery-4.1.0.min.js"></script>
<style>
body { margin: 1rem; color: #172633; font: 1rem/1.6 system-ui, sans-serif; }
main { max-width: 38rem; margin: auto; }
fieldset { min-inline-size: 0; margin-block: 1rem; border: 1px solid #708896; }
input[type="number"] { box-sizing: border-box; max-width: 100%; width: 8rem; font: inherit; }
output { font-weight: 700; }
label { cursor: pointer; }
</style>
</head>
<body>
<main>
<h1>Detect input changes with jQuery</h1>
<fieldset>
<legend>Multiply two numbers</legend>
<p><label for="a">A</label> <input type="number" id="a" step="any"></p>
<p><label for="b">B</label> <input type="number" id="b" step="any"></p>
<p>While editing <output id="live" for="a b" aria-live="off">—</output></p>
<p>After commit <output id="committed" for="a b">—</output></p>
</fieldset>
<fieldset>
<legend>Checkbox</legend>
<label><input type="checkbox" id="option"> Enable notifications</label>
<p><output id="checked" for="option">Unchecked</output></p>
</fieldset>
<fieldset id="fruits">
<legend>Choose a fruit</legend>
<label><input type="radio" name="fruit" id="apple" value="apple"> Apple</label>
<label><input type="radio" name="fruit" id="banana" value="banana"> Banana</label>
<p><output id="picked" for="apple banana">—</output></p>
</fieldset>
</main>
<script>
$(function () {
function product() {
const a = document.querySelector("#a").valueAsNumber;
const b = document.querySelector("#b").valueAsNumber;
const result = a * b;
return Number.isFinite(result) ? String(result) : "—";
}
$("#a, #b")
.on("input", () => $("#live").text(product()))
.on("change", () => $("#committed").text(product()));
$("#option").on("change", function () {
$("#checked").text($(this).prop("checked")
? "Checked" : "Unchecked");
});
$("#fruits").on("change", 'input[name="fruit"]', function () {
const label = this.labels[0].textContent.trim();
$("#picked").text(label + " (" + $(this).val() + ")");
});
});
</script>
</body>
</html>
Type 2 in A, move to B, and type 3. While B still has focus, the live result shows 6 and the committed result shows —. Tab away from B and the committed result becomes 6 too. valueAsNumber reads numbers and the example displays — for an empty or invalid result. A real zero produces 0.
Read checkbox and radio selections
Select and clear the checkbox. $(this).prop('checked') reads its current state as a boolean. .val() returns the configured checkbox value, which does not tell you whether it is checked.
Both radio buttons share name="fruit", allowing one selection. Switching from Apple to Banana fires change on the newly selected Banana button. In the handler, this is that radio button and $(this).val() gives its stored value, such as banana.
Update results after changing a value in code
Running .val('4') changes the control’s value without dispatching the user-input events. If the same handlers need to run, trigger the relevant events explicitly after setting the value. See the jQuery .val() documentation for details.
$("#a").val("4");
$("#a").trigger("input").trigger("change");
With both results at 6, open the developer console and run the first line alone. A becomes 4 and the outputs still read 6. Run the second line to update both outputs to 12. If your page has one update function, calling it directly is also an option.
Troubleshoot a handler that does not run
If nothing updates, check whether jQuery loaded in the Network panel and whether the selector matches the actual controls. If only typing works, check for a keyup handler. For checkboxes, inspect the live checked property.
For radio buttons added later, the example registers the handler on the persistent #fruits container and passes the radio selector as the second argument. This is event delegation.




