Forms and Storage
Forms are how people talk to your page. Read what they typed, choose the right form event, stop a form that isn't ready, show helpful error messages, and remember their data with localStorage so it's still there tomorrow.
Updated
Forms in JavaScript
- Reading What People Type (Apprentice): Read what a visitor typed, ticked and chose in a form with value and checked, turn text into numbers, and collect a whole form at once with form.elements or FormData.
- Form Events (Apprentice): Form controls send their own events, for the moments a visitor types, changes a value, moves between fields or sends the form, so you can pick the one that fires exactly when you need it.
- Canceling Events (Journeyman): A handler can cancel what the browser would do next, such as sending a form that failed validation, by calling preventDefault() on the event object the browser passes in.
- Checking a Form with JavaScript (Journeyman): Let the browser check a form with required, min and type, ask it in code with checkValidity(), add rules of your own with setCustomValidity(), and show each error next to its field where everyone, screen reader users included, can find it.
Storage in the Browser
- Remembering Data with localStorage (Apprentice): Make a page remember things between visits with localStorage, save whole lists with JSON, start cleanly when nothing is saved yet, and know what sessionStorage and cookies are for and what must never be stored in the browser.
Exercise: Reading List
- Exercise: Reading List (Journeyman): Make a reading-list page work, reading its add-book form, refusing a book with no title or 0 pages with a message next to the field, and saving the list in localStorage so it's still there tomorrow, with tests for the rules and a checklist for the page.
Up Next: Waiting for Data
- Up Next: Waiting for Data (Apprentice): See how much of a web page you can now control, meet the Photo Gallery project where you'll show it, and find out why a page freezes when code waits the wrong way, and what Module 5's timers, promises and fetch change.