Skip to content
FunnelGuard

Fix guide by FunnelsGuard

JS error after clicking submit breaks the form: how to fix it

PRF-120High impactDetectedBy FunnelGuardPublished Updated
On this page

What this issue is

Most JavaScript error checks look at page load. This issue is different. The page loads with a clean console, the form looks normal, and the error only appears when someone clicks submit. The code that runs on that click throws an exception, and the form stops partway.

The code running on submit is usually one of these: a validation script, a custom submit or click handler, a tracking call (for example a conversion event that reads a field that does not exist), a CAPTCHA callback, or a script that builds the request to send to your CRM. If one of them throws, later code in the same handler never runs. That can include the code that actually sends the form.

Why it costs you leads or sales

The visitor has done the hard part. They found your page, filled in the form and clicked. If the click ends in a script error, they usually see nothing: no thank-you message, no error, no page change. Most people click once or twice more, then leave.

Where a submit-time error breaks the funnel
  1. Landing pageLoads with a clean console
  2. Fill in formFields accept input
  3. Click submitHandler throws an error
  4. Form request sentNever runs
  5. Lead in inbox / CRMNothing arrives
  6. Conversion trackedNo thank-you event

The page and the form work. The break happens in the click handler, so everything after it is lost.

Leads per week before and after a submit error appearsExample numbers
Leads per week before and after a submit error appears (example)Week 1: 42 leads; Week 2: 40 leads; Week 3: 6 leads; Week 4: 5 leads01632424065Week 1Week 2Week 3Week 4leads

Example: the same traffic, but a theme update introduces a submit error in week 3. Numbers are illustrative.

How to check if your site has it

You have to reproduce the click. Looking at the page is not enough.

Reproduce the error in your browser
  1. Open DevTools before you click

    Press F12 (or Cmd+Option+I on Mac) and open the Console tab. Tick Preserve log so the error stays if the page reloads.

  2. Fill in the form with test data

    Use a clearly fake name and an email you control. Fill in every field the way a real visitor would.

  3. Click submit and read the first red error

    Note the message and the file and line number on the right. The first error matters most, because later ones are often side effects.

  4. Check the Network tab

    If no request to your form endpoint appears after the click, the script stopped before sending. If a request appears with a 4xx or 5xx status, that is a different problem (server side).

  5. Repeat in a private window and another browser

    A private window with extensions off rules out browser add-ons. A second browser shows whether the error is browser specific.

Common submit-time errors and what they usually mean
Console messageLikely causeWhere to look
Cannot read properties of null (reading 'value')Script looks for a field that was renamed or removedCustom validation or tracking code
x is not a functionA library did not load, or loaded twice with a clashScript order, duplicate jQuery
x is not definedA variable such as dataLayer or fbq is missingTag or pixel snippet
Uncaught (in promise) TypeErrorAn async call failed and nothing handles itFetch or CRM integration code
Failed to execute 'submit' on 'HTMLFormElement'A field is named submit and hides the submit methodForm markup

How to fix it

The error message tells you which script to fix. Fix the cause, not just the symptom. Wrapping everything in a try/catch hides the error but may still leave the form unsent.

Fix the failing submit handler
  1. Find the file and line

    Click the file link next to the error in the Console. Note whether it is your theme, a plugin, a tag manager script or a third-party widget.

  2. Disable the suspect script and test again

    Turn off the plugin, tag or snippet and submit again. If the error goes away, you have found the source.

  3. Correct the code or update it

    Fix the selector, add a null check, or update the plugin or theme to a version that matches your current form.

  4. Make tracking code fail safely

    Tracking should never block the form. Guard calls so a failure in analytics cannot stop the send.

  5. Submit again and check the lead arrives

    Confirm the console is clean, the network request succeeds and the test lead reaches your inbox or CRM.

Guard a submit handler so tracking cannot block the formjavascript
document.querySelector('#lead-form').addEventListener('submit', function (event) {
  // Tracking is optional: never let it stop the form.
  try {
    var emailField = document.querySelector('#email');
    if (emailField && window.dataLayer) {
      window.dataLayer.push({ event: 'generate_lead' });
    }
  } catch (err) {
    console.warn('Tracking failed', err);
  }
  // The form then submits normally.
});
Where to look on each platform
  1. Find the culprit plugin

    Use the file path in the error. Paths containing /wp-content/plugins/name/ point to that plugin. Update it, or deactivate plugins one by one and retest the form.

  2. Check theme and form plugin versions

    A form builder (Contact Form 7, Gravity Forms, WPForms and similar) can clash with a theme or optimisation plugin. Update all three.

  3. Exclude the form scripts from JS optimisation

    If a caching or minify plugin combines, delays or defers JavaScript, exclude the form plugin's scripts and jQuery, then clear the cache and test again.

How to confirm it's fixed

Confirmation checklist
  • The Console shows no red error after you click submit
  • The Network tab shows the form request with a 2xx status
  • The visitor sees a thank-you message or page
  • The test lead arrives in your inbox and CRM
  • Your conversion tag fires once on success
  • The same result in Chrome, Safari and a mobile browser
  • The same result in a private window with extensions off
Submit click before and after the fix

Before

  • Console shows an uncaught TypeError on click
  • No network request to the form endpoint
  • Visitor sees nothing happen
  • No lead, no conversion event

After

  • Console stays clean on click
  • Form request returns a 2xx status
  • Thank-you message or page shown
  • Lead and conversion event both recorded

How to prevent it happening again

Prevention habits
  • Test a full form submission, not just the page load, after every theme, plugin or tag change
  • Keep tracking code wrapped so it cannot block the send
  • Avoid renaming field IDs or classes without searching your scripts for them
  • Publish tag manager changes in preview first and submit the form in preview
  • Update form plugins and themes in a staging copy before production
  • Run a scheduled test that submits the form and checks the lead arrives
How a silent submit error usually unfolds
  1. Day 0

    A plugin or tag update changes how the form is built. The page still looks fine.

  2. Day 0

    The first visitor clicks submit and the handler throws. Nothing is sent.

  3. Day 1-3

    Leads drop, but ad spend and traffic look normal, so nobody investigates.

  4. Day 4

    Someone submits the form by hand, sees the error and traces it to the script.

  5. Day 4

    The script is fixed and leads return. Example timing only.

How FunnelGuard handles this

FunnelGuard detects this issue today. A robot visitor runs your real form journey on a schedule, fills in the form and clicks submit. It records console errors at each step, including the ones that only appear after the click, and checks whether the submit actually worked.

If a step fails, FunnelGuard re-checks from a second region before it sends one alert (email, Slack, Teams, WhatsApp, webhook or PagerDuty) with a screenshot and a likely cause. It can also check whether the test lead reaches your inbox and CRM, and whether tracking hits are sent. Test traffic is marked with utm_source=funnelguard and fg_test=1, and it never bypasses CAPTCHAs or bot protection. If your form is protected by one, the test may not be able to complete the submit.

Questions people ask

Why does my form show a JavaScript error only when I click submit?

The code that runs on submit (validation, tracking, a CRM call or a CAPTCHA callback) is different from the code that runs on page load. If one of those scripts looks for a field that is missing or a library that did not load, it throws only at that moment. Open the Console, click submit and read the first red error to see which script it is.

Why is my submit button not working and nothing happens?

Often a script error stops the click handler before the form is sent. Open DevTools, go to Console and click the button. If you see a red error and no request in the Network tab, a script is breaking the submit.

How do I find which script breaks my form on submit?

Click the file name next to the error in the Console. A path in /wp-content/plugins/ points to a WordPress plugin, and a tag manager script points to a Custom HTML tag. Disable that script, resubmit, and if the error is gone you have found it.

Can a tracking pixel stop my form from submitting?

Yes. If a tracking call runs inside the submit handler and throws an error, the code after it may never run, including the send. Wrap tracking in a try/catch or load it so it cannot block the form.

Will I get an error email when a form fails because of JavaScript?

Usually not. The browser throws the error, and your server never receives a request, so it has nothing to report. You only notice through fewer leads or by testing the form yourself.

How can I monitor my form for submit errors automatically?

You need a test that fills in and submits the form on a schedule and watches the console. FunnelGuard does this with a robot visitor, checks the step, the tracking hits and whether the test lead arrives, and alerts you with a screenshot and likely cause.

Is a try/catch around the submit handler enough to fix it?

No. It hides the error from the console but does not fix the broken script, and the form may still not send. Fix the root cause, then confirm a test lead reaches your inbox or CRM.

Does FunnelGuard catch this?

Detected

FunnelGuard checks for this today.

How: console errors per step + submit fails.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.