RadioNodeList Reads Checked Radio Groups
Read named radio groups via form.elements and RadioNodeList.value, and clear the group by unchecking each input: assigning '' is not a reset.
Code
const form = document.querySelector('#shipping');
const group = form.elements.namedItem('speed');
// RadioNodeList.value returns the checked radio's value,
// or '' when nothing is checked yet.
console.log('initial:', JSON.stringify(group.value));
// Setting value through the list checks the matching radio for you.
group.value = 'express';
console.log('after set:', group.value);
// The list is iterable: every input in the group, in DOM order.
for (const radio of group) {
console.log(radio.value, radio.checked);
}
// The HTMLFormControlsCollection also indexes by name directly.
console.log('same group:', form.elements['speed'] === group);
// Assigning '' is NOT a reset: the value setter only ever checks a radio
// whose value matches, so an empty assignment leaves the choice untouched
// (verified in Chromium: the read-back is still 'express').
group.value = '';
console.log('still selected after assigning "":', JSON.stringify(group.value));
// Reading an untouched group never throws — '' is the 'nothing checked' signal.
// Clearing requires unchecking each input directly:
for (const radio of group) {
radio.checked = false;
}
console.log('cleared:', JSON.stringify(group.value));Inside the code
The file’s state is a handful of top-level bindings: form, group.
What to watch for
- Nothing to vet in a supply-chain review — the file pulls in no packages.
- The snippet leans on
document— browser-only surfaces a bare Node process cannot provide.
Applying it
Look for the initial:, after set:, same group: markers as the output appears; each one traces back to a step.
Statements to notice
const form = document.querySelector('#shipping');
const group = form.elements.namedItem('speed');
group.value = 'express';
Interactive Tools for This Topic
JSON to Zod Schema ConverterInfer typed Zod z.object schemas from JSON payloads locally, supporting nested objects, merged array shapes, enums, nullable fields, and JSDoc comments.JSON Schema ValidatorValidate JSON data against a JSON Schema definition and get detailed error reports. Supports type checking, required fields, and common constraint validation.JSONL / NDJSON InspectorValidate NDJSON and JSON Lines line-by-line, pinpoint syntax errors by line number, analyze key frequencies and types, and export a pretty JSON array.Credit Card Brand DetectorIdentify the card network from a number's prefix and length, validate the Luhn checksum, and show a masked form and the issuer identification number.
FAQ
- Does RadioNodeList Reads Checked Radio Groups run in plain Node.js?
- No — it touches `document`, which exist only in the browser. Run it in a page (or the DevTools console) instead of a bare Node process.
Report a problem with this exampleOpens a pre-filled issue on GitHub.