Every form control has a value: input.value for text boxes, select.value for drop-downs. Values are always strings, even in type="number" inputs.
Checkboxes and radio buttons are on or off: read checkbox.checked (true/false). Their value is the label you gave them, not whether they are ticked.
form.elements.name finds a control by its name attribute, which is what the browser uses when the form is sent. For a group of radio buttons with the same name, form.elements.plan.value is the chosen one.
new FormData(form) collects every named, enabled, successful control at once. Object.fromEntries(new FormData(form)) turns it into a plain object.
Convert on read: Number(input.value) or input.valueAsNumber (which gives NaN for an empty field) for numbers, input.valueAsDate for date inputs. Validate before trusting the result.
FormData skips unchecked checkboxes and disabled fields entirely. If the absence of a key matters, read .checked directly or use formData.has("terms").
Several checkboxes can share a name; formData.getAll("topics") returns every checked value as an array, while Object.fromEntries would keep only the last.
Trim text values (value.trim()) before checking or storing them; people paste trailing spaces and line breaks.
05Definitions
Form control
An element that collects input, such as input, select, textarea or a button.
value
The current string value of a form control.
checked
A boolean property telling whether a checkbox or radio button is selected.
form.elements
A collection of a form's controls, accessible by name or index.
FormData
An object that collects a form's named values as key/value pairs.
An online shop reads quantity, size and gift-wrap choices from the product form, converts quantity to a number, and builds an order object before sending it. Unchecked boxes are handled explicitly so the server always gets true or false.
const raw = { qty: "2", size: "M" };
const order = { qty: Number(raw.qty), size: raw.size, gift: "gift" in raw };
console.log(JSON.stringify(order));
12Knowledge check
1. What type is input.value for <input type="number">?
number
string
bigint
It depends on the content
2. Two number inputs hold 4 and 5. What does a.value + b.value give?
5. How do you read the selected radio in a group named plan?
form.elements.plan.value
form.plan.checked
document.querySelector("[name=plan]").value
form.elements.plan[0].value
6. Several checkboxes share name="tag". Which reads all checked values?
Object.fromEntries(new FormData(form)).tag
new FormData(form).getAll("tag")
form.elements.tag.value
form.tag.checked
13Solutions and tests
Each exercise's solution appears in the exercise once you have run its tests. Solutions are one possible answer: the tests accept any implementation with the same behaviour.
Automated acceptance tests for this lesson
These are the same checks the exercises run. They are visible on purpose: client-side tests help you learn and are not secret.
The total is 1020: Prints Total: 30; total is a number
Read an order form: Prints the order; Follows changes
A complete form reader: Prints the object; One checked value stays a string
The lesson lives in the companion repository at curriculum/level-03-interactive-web-applications/module-13-forms-and-validation/lesson-061-reading-form-values/. Every example on this page is generated from those files.
These links open the files in the GitHub repository (https://github.com/lsvekis/JavaScript-Professional-Engineering-Academy). You can also use the ZIP download above.
15Summary and next steps
Form values are strings; convert numbers on read.
Checkboxes and radios report checked; value is their label.
form.elements finds controls by name.
FormData collects a whole form; unchecked and disabled fields are left out.
Copy a prompt into the AI assistant of your choice. Then verify what it says by running code here. No AI service is connected to this page.
Concept explanationreading form values
Context: I am learning reading form values in JavaScript.
Task: Explain how to read text, number, select, checkbox and radio values, and FormData.
Constraints: Beginner-friendly language, short runnable examples, no libraries.
Expected behaviour: I can explain the idea in my own words and predict small programs.
Testing: Finish with three quick questions for me to answer.
Code predictionreading form values drill
Context: I have practised reading form values.
Task: Give me six short form-reading programs and ask what each prints.
Constraints: Wait for my answer before revealing each result.
Expected behaviour: Each question has exactly one correct output.
Testing: Explain any I miss with a step-by-step trace.
Debuggingreading form values bug
Context: My total of two input fields shows 1020 instead of 30.
Task: Help me find the cause with questions instead of giving me the fix.
Constraints: Do not rewrite my program.
Expected behaviour: I locate and fix the bug myself.
Testing: Suggest the console.log lines that would reveal the problem.
Exercise generationreading form values practice
Context: I finished the reading form values exercises.
Task: Create three exercises that read forms into objects with exact expected output.
Constraints: Fictional data and exact expected output.
Expected behaviour: Each exercise has tests I can run.
Testing: Put the solutions in a separate hidden section.
Code reviewreading form values review
Context: Here is my code that uses reading form values.
Task: Review my form-reading code for string/number mistakes and missing checkbox handling.
Constraints: Explain each suggestion briefly and keep behaviour identical.
Expected behaviour: The code is clearer and has no hidden mutation or edge-case bug.
Testing: List the changes in order of importance.