A community garden wants visitors to request watering and/or compost help. The starter has the name field and one checkbox. Complete the form, then use the preceding seed-swap demo to guide the JavaScript.
Here is a separate worked example for a library survey. The shared name groups checked fields, while textContent keeps the visitor's text literal:
<form id="library-form">
<label><input type="checkbox" name="format" value="Audio"> Audio</label>
<label><input type="checkbox" name="format" value="Print"> Print</label>
</form>
<p id="library-result" role="status"></p>
const survey = document.querySelector("#library-form");
const result = document.querySelector("#library-result");
const selected = new FormData(survey).getAll("format");
result.textContent = selected.length ? selected.join(", ") : "No formats chosen";
For the garden, do the read inside submit so each request uses the latest checkbox state. Prevent navigation and trim the visitor's name. An unchecked box is absent from FormData, not a value of false. Use textContent, not HTML insertion, for the output.
help checkbox with value Compost beside the existing Watering option.#garden-status a polite live status region.#garden-form is submitted.FormData.getAll("help"); report “no help selected” when none are checked.Try one check, both checks, and neither, resubmitting each time. Type <em>Jo</em> as a name: the output should show the angle brackets rather than create an emphasized element.
Give both checkboxes the same name but different values; getAll returns only checked values.
Read a new FormData(form) inside the submit handler, not once when the page loads.