CHAPTER 59 · HTML

Final project: a form with a working practice result page

Build a labelled form and read its submitted values. See the complete browser-side journey without pretending to build a booking or message service.

Download example files (ZIP)

The problem we will solve

Earlier forms helped you inspect names and values in the address bar. Now we will display those values in a second page. Imagine asking a classmate to check your study question before you send it anywhere. We need an alias, one topic and one short question. This is a local display exercise, not a real support form. Use invented details.

Plan both sides before writing

Save project-question.html and project-question-result.html in one folder. The first collects values; the second reads its own URL. Action names the second file. Method=get adds named form entries to that address. Both files must exist. The result page uses JavaScript, so enable it in your saved example and test over local HTTP using Chapter 57.

Choose understandable fields

The alias is text with a visible required instruction and a 30-character limit. Topic is a select with an empty first option; required means the person must choose a non-empty option. The question is a labelled textarea with a 200-character limit. The label for each control matches its id. Its name becomes the submitted key: alias, topic or question.

Rows and cols suggest the textarea size, not its allowed answer length. Maxlength sets that length limit in normal entry. Neither browser limits nor required prove received data is trustworthy. A person can edit a URL or send their own request.

Follow a sample submission

Enter the alias Kite, choose Links and type Which folder does this path use? Then press Display practice values. The browser opens the result filename with a query string: the part after ?. Entries are separated by &, and a key is joined to its value by =. Spaces and special characters may be encoded. You do not need to build this string yourself for a normal GET form.

GET values are visible in the address, history and potentially server logs. Do not use this design for passwords or private details. The local HTTP server may log the request URL even though our program has no database. In a real service, choose the right request method, HTTPS and appropriate server-side handling.

Read the result script slowly

Window.location.search gives the query-string part of the current address. New URLSearchParams(...) creates a helper that reads those entries and decodes their encoded characters. Values.get("alias") returns the first alias value, or null if there is none. The || expression uses Not provided when the returned value is missing or empty. Repeat the same process for topic and question.

GetElementById finds the visible destination. TextContent inserts the answer as plain text. It does not treat an answer containing angle brackets as a new HTML element. Do not replace it with innerHTML for visitor-supplied strings. The result intentionally displays the supplied topic; it does not approve that topic, authenticate the visitor or trust the address.

What the result page proves

Seeing the values proves that this browser followed the GET navigation and the result script read the address. It does not prove an email was sent, a teacher saw the question, a login was checked or a record was saved. Reloading the result reads the same URL again. Opening the result directly without a query shows Not provided.

A backend version would need a real receiving endpoint, trusted checks and suitable storage or delivery. It would also need honest error and success messages. Learn that after you understand HTML, CSS and JavaScript.

Test normal, missing and unusual values

Try submitting an empty form: the browser should point to a missing required answer. Fill all three fields and inspect the result. Open the result directly: all three values should be Not provided. Then type <b>hello</b> as a fictional question and submit. It should appear literally, not as bold markup.

Edit topic in the URL to an unexpected word. The display page should show that word because the address is editable; it has not validated a server request. Try keyboard navigation and narrow-screen reading. The embedded tutorial preview deliberately blocks scripts and form submission; these end-to-end checks need the saved files.

Extend only after the small version works

Add a session-count field to the form and a matching dt/dd pair to the result. Use a new name and unique id. Read the same submitted name in the result script. Explain how a missing count should display. Keep the scope honest: the extension still does not reserve sessions or create an account.

Follow the idea

Follow the practice form
  1. 1Enter fictional values
  2. 2GET adds named URL entries
  3. 3Read the result query
  4. 4Display plain text

Displaying values does not send a message or save a record.

Complete program: project-question.html

Save this as project-question.html. Open it in your browser.

project-question.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Practice Question Form</title>
  </head>
  <body>
    <h1>Prepare a fictional study question</h1>
    <main>
      <p>
        This local exercise displays values in the next page. It does not contact a teacher or save
        a request. Use made-up details; GET values appear in the URL.
      </p>
      <form action="project-question-result.html" method="get">
        <p>
          <label for="question-alias">Practice alias (required, up to 30 characters)</label>
          <input id="question-alias" name="alias" type="text" required maxlength="30" />
        </p>
        <p>
          <label for="question-topic">Topic (required)</label>
          <select id="question-topic" name="topic" required>
            <option value="">Choose a topic</option>
            <option value="links">Links</option>
            <option value="forms">Forms</option>
          </select>
        </p>
        <p><label for="question-text">Practice question (required, up to 200 characters)</label></p>
        <p>
          <textarea
            id="question-text"
            name="question"
            rows="4"
            cols="28"
            required
            maxlength="200"
          ></textarea>
        </p>
        <button type="submit">Display practice values</button>
      </form>
    </main>
  </body>
</html>
Browser previewDocument title: Practice Question Form

This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here. Form submission is disabled in this preview. Save the example and its result page locally to test submission. Use fictional practice values.

Expected result: three labelled required controls and Display practice values. An empty submission is blocked by normal browser validation. With both files served locally, a completed submission opens the result page with a query string.

Complete program: project-question-result.html

Save this as project-question-result.html. Open it in your browser.

project-question-result.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Practice Question Result</title>
  </head>
  <body>
    <h1>Read your practice values</h1>
    <main>
      <p>
        This page reads its URL. Nothing was booked, sent to a teacher or stored in a database.
        Anyone can change these URL values.
      </p>
      <dl>
        <dt>Practice alias</dt>
        <dd id="result-alias">Not provided</dd>
        <dt>Topic</dt>
        <dd id="result-topic">Not provided</dd>
        <dt>Question</dt>
        <dd id="result-question">Not provided</dd>
      </dl>
      <p><a href="project-question.html">Return to the practice form</a></p>
      <script>
        const values = new URLSearchParams(window.location.search);
        document.getElementById('result-alias').textContent = values.get('alias') || 'Not provided';
        document.getElementById('result-topic').textContent = values.get('topic') || 'Not provided';
        document.getElementById('result-question').textContent =
          values.get('question') || 'Not provided';
      </script>
    </main>
  </body>
</html>
Browser previewDocument title: Practice Question Result

This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here. JavaScript does not run in this preview. Save the complete example and any named script file together to test its actions or canvas drawing in your browser.

Expected result: the submitted alias, topic and question appear as plain text. Without query values, each says Not provided. The return link opens the form; it does not promise to restore previous form entries.

Problem and solution

Problem: a page says Message sent after merely navigating to another HTML file.

Solution: use a truthful label such as Practice values displayed. Read and show the values explicitly. Only claim successful delivery when a real receiving service has confirmed the appropriate action.

Common mistakes and useful tips

  • Names in the script must match form names, not just ids.
  • Use plain text insertion for answers.
  • Do not collect secrets with GET.
  • A display page is not trusted server validation.
  • Opening a static page is not proof of sending or saving.

Practice questions

  1. What must action match?
  2. Which attribute identifies the submitted alias key?
  3. What does URLSearchParams.get return when a key is absent?
  4. Why use textContent?
  5. Does changing the URL prove the visitor is authorised?
  6. Add a count field and describe every matching change.
Check your practice answers
  1. The actual result filename and path: project-question-result.html in this exercise.
  2. Name=alias. Id connects the label and control.
  3. Null. The example displays Not provided through the fallback expression.
  4. It displays the answer as plain text rather than interpreting supplied markup.
  5. No. URL values are editable; this exercise does not authenticate anyone.
  6. Add its label, unique id and name to the form; add a result destination; read that name with get and insert its value as text with a missing-value fallback.

Interview questions

How does a GET form reach this result page?

The browser constructs a query string from submitted named controls and navigates to action. The result script reads that address and fills visible text.

Is browser validation enough for a real service?

No. It improves ordinary entry, but callers can bypass it. The receiving service must perform its own trusted checks.

Why is a static success page misleading?

A page opening only proves navigation. Without a receiver and confirmation, it cannot honestly claim delivery, storage or a booking.

Does textContent solve every security problem?

No. It is appropriate for plain text output here. Real services still need suitable authentication, checks and safe handling in every other context.

Quick revision

  • Match labels, names and result destinations.
  • GET exposes values in the URL.
  • Read the query and insert plain text.
  • Display is different from sending or storing.