DEV Community

Looms VN
Looms VN

Posted on

Make a contact form’s success message audible without moving focus

Try submitting a contact form with a screen reader while leaving keyboard focus on the Send button. The green confirmation may appear on screen while the reader says nothing. A useful fix is to put the confirmation in a status region that already exists when the page loads.

Here is a minimal example. The callback belongs in the success branch of the form handler, after the server has accepted the enquiry.

<button type="submit">Send enquiry</button>
<p id="enquiry-status" role="status"></p>
Enter fullscreen mode Exit fullscreen mode
function showEnquiryReceipt(reference) {
  const status = document.getElementById('enquiry-status');
  status.textContent = 'Enquiry received. Your reference is ' + reference + '.';
}
Enter fullscreen mode Exit fullscreen mode

The empty paragraph does two jobs. It gives sighted readers a stable place to find the receipt, and its status role asks assistive technology to announce changes politely. Keep it in the accessibility tree while empty. Making the paragraph with display: none and revealing it at the same moment as the text can make the announcement unreliable. The reference in this example is a fictional enquiry number such as DEMO-42.

A quick acceptance check

  1. With a screen reader on, tab to Send enquiry and activate it. Keep your hands off the keyboard until the test response arrives.
  2. For a successful test response, listen for the reference once. Confirm that the same reference is visible and that keyboard focus is still on Send enquiry.
  3. Repeat with an unsuccessful response. The success receipt must stay empty. Show a distinct, visible error and keep the entered message available so the visitor can retry.

This example covers an in-place submission. A form that navigates to a new confirmation page needs a meaningful page title and heading as well. Test the interaction with the browser and screen reader your visitors actually use.

Written by Looms VN for teams maintaining the enquiry forms on their websites.

Top comments (0)