Created
October 17, 2024 23:38
-
-
Save chrisegg/02489abe087722ccba4c1fd95bd5c6dc to your computer and use it in GitHub Desktop.
This snippet will change a selection in a radio button field when entering a value to another field.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Gravity Ranger // Gravity Forms // Change radio button choice when adding value to another field | |
* https://gravityranger.com/gravity-forms-fancy-donation-form | |
* | |
* This snippet will change a selection in a radio button field when entering a value to another field. | |
* Intended for a donation form with a price select field and and a user defined price field. | |
* | |
*/ | |
<script type="text/javascript"> | |
document.addEventListener('DOMContentLoaded', function() { | |
// Get the price field | |
var priceField = document.querySelector('#input_612_4'); // Price field: form ID 612, field ID 4 | |
// Get the specific radio buttons (choices) by their individual IDs | |
var otherOption = document.querySelector('input#choice_612_14_4'); // Other choice (value other) | |
// Add event listener for when the price field is manually changed | |
priceField.addEventListener('input', function() { | |
// Automatically select the "Other" radio button when the user types into the price field | |
if (otherOption) { | |
otherOption.checked = true; // Select the "Other" option | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment