# Conditional Logic to Replace Elfsight Form Submit Button

**URL:** <https://community.elfsight.com/t/conditional-logic-to-replace-elfsight-form-submit-button/141114>\
**Category:** Customization\
**Tags:** form-builder, squarespace\
**Created:** [November 4, 2025, 2:59am UTC](https://community.elfsight.com/t/conditional-logic-to-replace-elfsight-form-submit-button/141114 "2025-11-04T02:59:23Z")\
**Posts on this page:** 11\
**Page:** 2

<div class="post-metadata">

**Author:** ![Michael\_Surnak](https://sea2.discourse-cdn.com/flex020/user_avatar/community.elfsight.com/michael_surnak/32/82394_2.png) [@Michael\_Surnak](https://community.elfsight.com/u/Michael_Surnak)\
**Post date:** [January 11, 2026, 7:19am UTC](https://community.elfsight.com/t/conditional-logic-to-replace-elfsight-form-submit-button/141114/22 "2026-01-11T07:19:46Z")

</div>

Thank you, Max.

I tested it and it works well initially, but if a customer goes back in the form after triggering the button, clicking the next button still opens the “Get Your Free Quote” page instead of behaving normally. I’ve recorded a screen capture to demonstrate the issue. Could this be a limitation of the JavaScript?

---

<div class="post-metadata">

**Author:** ![Max](https://sea2.discourse-cdn.com/flex020/user_avatar/community.elfsight.com/max/32/710_2.png) [@Max](https://community.elfsight.com/u/Max)\
**Post date:** [January 11, 2026, 10:33am UTC](https://community.elfsight.com/t/conditional-logic-to-replace-elfsight-form-submit-button/141114/23 "2026-01-11T10:33:17Z")

</div>

Got it, thanks for sharing a screencast!

I really hope this behavior can be adjusted. Our devs will look into this and I’ll update you once it’s done 🙂

---

<div class="post-metadata">

**Author:** ![Max](https://sea2.discourse-cdn.com/flex020/user_avatar/community.elfsight.com/max/32/710_2.png) [@Max](https://community.elfsight.com/u/Max)\
**Post date:** [January 13, 2026, 10:26am UTC](https://community.elfsight.com/t/conditional-logic-to-replace-elfsight-form-submit-button/141114/24 "2026-01-13T10:26:42Z")

</div>

Hi @Michael_Surnak 👋

We’ve adjusted the script:

```auto
const widgetSelector =
  '.elfsight-app-17536663-c388-4d9c-900b-ac172987f487';

const newButtonLink =
  'https://k9poopertroopers.com.au/get-your-free-quote';

const originalTextMap = new WeakMap();
const patchedInputs = new WeakSet();
const boundButtons = new Set();

const rules = [
  {
    labelStartsWith:
      'What changes would you like to make to your service address/addresses?',
    inputSelector: 'input[value="Change a service address"]',
    buttonText: 'Get Your Free Quote'
  },
  {
    labelStartsWith:
      'How many service addresses would you like to add?',
    inputSelector: 'input[value="Just one"]',
    buttonText: 'Get Your Free Quote'
  },
  {
    labelStartsWith:
      'How many service addresses would you like to add?',
    inputSelector: 'input[value="Multiple"]',
    buttonText: 'Get Your Free Quote'
  }
];

function getActiveRule(container) {
  for (const rule of rules) {
    const field = [...container.querySelectorAll('[class*="FormFieldLayout__Container-sc"]')]
      .find(f => {
        const labelEl = f.querySelector('[class*="FormFieldLayout__Label-sc"]');
        return (
          labelEl &&
          labelEl.textContent
            .trim()
            .toLowerCase()
            .startsWith(rule.labelStartsWith.toLowerCase())
        );
      });

    if (!field) continue;

    const input = field.querySelector(rule.inputSelector);
    if (input && input.checked) {
      return rule;
    }
  }

  return null;
}

function patchStep(container) {
  const buttonEl = container.querySelector(
    'button[aria-label="Submit Change Request"]'
  );

  if (!buttonEl) return;

  const buttonLabel =
    buttonEl.querySelector('[class*="ButtonBase__Ellipsis-sc"]') ||
    buttonEl;

  if (!originalTextMap.has(buttonEl)) {
    originalTextMap.set(buttonEl, buttonLabel.textContent);
  }

  function syncButtonText() {
    const activeRule = getActiveRule(container);

    if (activeRule) {
      buttonLabel.textContent = activeRule.buttonText;
    } else {
      buttonLabel.textContent =
        originalTextMap.get(buttonEl) ?? buttonLabel.textContent;
    }
  }

  if (!boundButtons.has(buttonEl)) {
    boundButtons.add(buttonEl);

    buttonEl.addEventListener(
      'click',
      e => {
        const activeRule = getActiveRule(container);
        if (!activeRule) return;

        e.preventDefault();
        e.stopPropagation();
        window.open(newButtonLink, '_blank');
      },
      true
    );
  }

  rules.forEach(rule => {
    const field = [...container.querySelectorAll('[class*="FormFieldLayout__Container-sc"]')]
      .find(f => {
        const labelEl = f.querySelector('[class*="FormFieldLayout__Label-sc"]');
        return (
          labelEl &&
          labelEl.textContent
            .trim()
            .toLowerCase()
            .startsWith(rule.labelStartsWith.toLowerCase())
        );
      });

    if (!field) return;

    const input = field.querySelector(rule.inputSelector);
    if (!input) return;

    if (!patchedInputs.has(input)) {
      patchedInputs.add(input);
      input.addEventListener('change', syncButtonText);
    }
  });

  syncButtonText();
}

const waitForWidget = setInterval(() => {
  const container = document.querySelector(widgetSelector);
  if (container) {
    patchStep(container);
    setInterval(() => patchStep(container), 300);
    clearInterval(waitForWidget);
  }
}, 300);

```

  

Could you please test your widget once again and let me know if any issues appear on your end?

---

<div class="post-metadata">

**Author:** ![Michael\_Surnak](https://sea2.discourse-cdn.com/flex020/user_avatar/community.elfsight.com/michael_surnak/32/82394_2.png) [@Michael\_Surnak](https://community.elfsight.com/u/Michael_Surnak)\
**Post date:** [January 14, 2026, 12:53am UTC](https://community.elfsight.com/t/conditional-logic-to-replace-elfsight-form-submit-button/141114/25 "2026-01-14T00:53:57Z")

</div>

IT WORKS! Thank you Max, I wasn’t sure if it was possible. Thank you to you and the team!

---

<div class="post-metadata">

**Author:** ![Max](https://sea2.discourse-cdn.com/flex020/user_avatar/community.elfsight.com/max/32/710_2.png) [@Max](https://community.elfsight.com/u/Max)\
**Post date:** [January 14, 2026, 10:48am UTC](https://community.elfsight.com/t/conditional-logic-to-replace-elfsight-form-submit-button/141114/26 "2026-01-14T10:48:03Z")

</div>

Perfect, you’re always welcome 😉

---

<div class="post-metadata">

**Author:** ![Michael\_Surnak](https://sea2.discourse-cdn.com/flex020/user_avatar/community.elfsight.com/michael_surnak/32/82394_2.png) [@Michael\_Surnak](https://community.elfsight.com/u/Michael_Surnak)\
**Post date:** [February 10, 2026, 6:40am UTC](https://community.elfsight.com/t/conditional-logic-to-replace-elfsight-form-submit-button/141114/27 "2026-02-10T06:40:03Z")

</div>

Hi Max,

I recently updated my form widget installed on [this page](https://k9poopertroopers.com.au/get-your-free-quote) from “Success message” to “Redirect to URL” on submission—that way I can track submissions better with Facebook Pixel/GTM. Since making this change, the custom JavaScript that modifies the form button to be “Join Our Waiting List” (linking to [K9 Pooper Troopers – Join Our Waiting List](https://k9poopertroopers.com.au/join-our-waiting-list) ) when selecting “No” to the first question no longer works.

Do you have any idea why this might be happening? Sorry to bother you and the team about this again!

Thanks,  
Michael

---

<div class="post-metadata">

**Author:** ![Max](https://sea2.discourse-cdn.com/flex020/user_avatar/community.elfsight.com/max/32/710_2.png) [@Max](https://community.elfsight.com/u/Max)\
**Post date:** [February 10, 2026, 10:46am UTC](https://community.elfsight.com/t/conditional-logic-to-replace-elfsight-form-submit-button/141114/28 "2026-02-10T10:46:32Z")

</div>

Hi there, @Michael_Surnak 👋

This script is pretty complex, so changes in the settings might shake things up a bit. But no worries, our devs will adjust the script and I’ll update you once it’s done 😉

---

<div class="post-metadata">

**Author:** ![Michael\_Surnak](https://sea2.discourse-cdn.com/flex020/user_avatar/community.elfsight.com/michael_surnak/32/82394_2.png) [@Michael\_Surnak](https://community.elfsight.com/u/Michael_Surnak)\
**Post date:** [February 11, 2026, 4:10am UTC](https://community.elfsight.com/t/conditional-logic-to-replace-elfsight-form-submit-button/141114/29 "2026-02-11T04:10:13Z")

</div>

Thank you Max 🙂

---

<div class="post-metadata">

**Author:** ![Max](https://sea2.discourse-cdn.com/flex020/user_avatar/community.elfsight.com/max/32/710_2.png) [@Max](https://community.elfsight.com/u/Max)\
**Post date:** [February 12, 2026, 3:02pm UTC](https://community.elfsight.com/t/conditional-logic-to-replace-elfsight-form-submit-button/141114/30 "2026-02-12T15:02:09Z")

</div>

Thank you for waiting!

We’ve adjusted the script and it’s working fine now. Please check it out 😉

---

<div class="post-metadata">

**Author:** ![Michael\_Surnak](https://sea2.discourse-cdn.com/flex020/user_avatar/community.elfsight.com/michael_surnak/32/82394_2.png) [@Michael\_Surnak](https://community.elfsight.com/u/Michael_Surnak)\
**Post date:** [February 13, 2026, 4:17am UTC](https://community.elfsight.com/t/conditional-logic-to-replace-elfsight-form-submit-button/141114/31 "2026-02-13T04:17:43Z")

</div>

Amazing. Thank you Max and the team!

---

<div class="post-metadata">

**Author:** ![Max](https://sea2.discourse-cdn.com/flex020/user_avatar/community.elfsight.com/max/32/710_2.png) [@Max](https://community.elfsight.com/u/Max)\
**Post date:** [February 13, 2026, 10:10am UTC](https://community.elfsight.com/t/conditional-logic-to-replace-elfsight-form-submit-button/141114/32 "2026-02-13T10:10:08Z")

</div>

No sweat!

We’re always here to help if any questions come up 😉

[Previous page](https://community.elfsight.com/t/conditional-logic-to-replace-elfsight-form-submit-button/141114.md?page=1)
