Change Radio Button Selection When Typing a Custom Value in Gravity Forms

11 hr ago

3 Min. Read

Share URL

This page may contain affiliate links. Please read my disclaimer for more information.

The Problem

You have a donation form with preset amount options ($10, $25, $50) and an “Other” option where users can type their own amount. The problem: when a user starts typing into the custom price field, the “Other” radio button doesn’t automatically select itself. The form still thinks they chose one of the preset amounts, or worse, nothing at all.

Gravity Forms has no built-in setting for this. The radio button and the text field are independent elements, so typing in one doesn’t affect the other.

The Solution

A lightweight JavaScript snippet that watches the custom amount field and automatically checks the “Other” radio button as soon as the user starts typing.

Complete Code Snippet

<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
    // === CONFIGURATION ===
    // Replace these with your actual form and field IDs.
    // You can find them by inspecting the form in the browser.
    var formId  = 612;    // Your form ID
    var priceFieldId = 4; // The custom price text field ID
    var choiceValue = 'other'; // The choice value/label of the "Other" option

    // Get the price field
    var priceField = document.querySelector('#input_' + formId + '_' + priceFieldId);

    // Get the "Other" radio button by its choice value attribute
    var otherOption = document.querySelector(
        'input[name="input_' + priceFieldId + '"][value="' + choiceValue + '"]'
    );

    if (!priceField || !otherOption) {
        console.warn('Gravity Ranger: Price field or Other option not found.');
        return;
    }

    // Auto-select the Other option
    function autoSelectOther() {
        if (otherOption && !otherOption.checked) {
            otherOption.checked = true;
        }
    }

    // When the user types into the price field
    priceField.addEventListener('input', autoSelectOther);

    // Also auto-select if a value already exists (e.g., after a validation error reload)
    if (priceField.value && priceField.value.trim() !== '') {
        autoSelectOther();
    }
});
</script>

What to Replace

VariableWhere to Find It
formIdForm Settings → Form ID
priceFieldIdField Settings → Field ID (your custom amount text field)
choiceValueRadio Button Field → Choices → Value of your “Other” option

Where to Add the Code

  • Add the code to an HTML field inside the form (it will execute while the user fills out the form).
  • Or use a plugin like WPCodeBox to load the snippet on the specific page.

A More Flexible Version (Event Delegation)

If your form uses AJAX or dynamically reloads, use this event-delegation approach that listens on the document level:

<script type="text/javascript">
document.addEventListener('input', function(e) {
    var formId = 612;
    var priceFieldId = 4;
    var choiceValue = 'other';

    // Only react when our specific price field is modified
    if (e.target.matches('#input_' + formId + '_' + priceFieldId)) {
        var otherOption = document.querySelector(
            'input[name="input_' + priceFieldId + '"][value="' + choiceValue + '"]'
        );
        if (otherOption && !otherOption.checked) {
            otherOption.checked = true;
        }
    }
});
</script>

Limitations & Caveats

  • This snippet works on the frontend only. It does not validate server-side that the “Other” option was selected.
  • If the user clears the custom price field, the radio button stays selected. Add an extra blur or change listener if you want to deselect when empty.
  • Always test with JavaScript disabled to ensure your form logic still makes sense without the enhancement.

Need More Help?

If you still need help, feel free to use the comments or chat options below.

Photo of author
About the Author
Chris Eggleston
Husband. Father of 4. Grandpa of 2. Chief Problem Solver exploring business systems, technology, AI & faith — helping people solve real problems. @mantiswp @chrisegg

Support Chris - Donate $5

Gravity Wiz Add-Ons

Advertisement

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments

Related Post

Change Radio Button Selection When Typing a Custom Value in Gravity Forms

A lightweight JavaScript snippet that automatically selects the "Other" radio button when a user types a custom donation amount into a Gravity Forms text field.

11 hr ago

3 min. read

Styling Gravity Forms Radio Buttons Like Toggle Switch

Problem I recently had someone ask if it was possible to style radio buttons like a toggle switch in Gravity...

Mar 17, 2026

4 min. read

Automatically Switch from a Registration Form to a Waitlist in Gravity Forms

This tutorial shows you how to automatically switch from a registration form to a waitlist form in Gravity Forms using entry limits or attendee tracking with a custom shortcode.

Sep 29, 2025

4 min. read

Using AI + Gravity Forms to Streamline Job Applications

Hiring is tough. Sorting through dozens, or even hundreds, of job applications is time-consuming, repetitive, and prone to human bias. That’s where combining Gravity Forms, Gravity Flow, and AI automation comes in.

Sep 26, 2025

2 min. read

Turn Gravity Forms Image Choice Field into carousel

Problem Recently, I saw a Gravity Forms user looking for a way to style the new Image Choice field. Specifically,...

Jul 14, 2025

3 min. read

Offer Subscription With One-Off Add-On Product Options with Gravity Forms

Want to offer a subscription + one-time add-ons in Gravity Forms? Here’s how to do it using Stripe’s setup fee feature in a single payment feed.

Mar 24, 2025

2 min. read