JavaScript AcademyProfessional Engineering

Learning object 43 of 100

Form data inspector

Fill in a live form and see each control's value and checked state, the FormData it produces, and the order of input, change and submit events.

Loading…

What it shows

Every form control has a string value. Checkboxes and radios also have checked. FormData collects every named, enabled control, but leaves out unchecked checkboxes and disabled fields, and keeps repeated names as separate entries that getAll returns together. input fires on every edit, change when an edit is committed, and submit on the form, where preventDefault stops the page from reloading.

Guided experiment

  1. Change the form in the preview and press Show data. Which fields are missing from FormData?
  2. Tick two topics and compare getAll with Object.fromEntries.
  3. In Event timeline, type in the field, leave it, then submit.

Predict

An unchecked checkbox named terms: what does new FormData(form).has("terms") return?

Related

Lessons: Lesson 61: Reading form values, Lesson 62: Input events and form submission

Projects: Project 9: Shopping Cart Price Calculator

Source: web/assets/js/objects/object-043.js in the companion repository.