Jquery to set Gravity Forms field
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

Using Gravity Forms with Authorize.net addon on highly customized Wordpress site. We have two products on the form, quantity for both need to be set the same. The first product quantity is set by dropdown; I was instructed that the second product's quantity would need to be set by jquery based on the first product. I have the following in custom.js to know avail. Need information on where to put the script and how to call it so it works on the form and a script that works, or an alternative solution to the problem.


$('#input_21_1').on('change', function() {

Script is called in header.php: /js/custom.js">

Crowdsource coding tasks.

2 Solutions

I think having your code in the custom.js should be fine as long as it appears on the page you are looking at. I'm making a couple assumptions about your inputs but that the first is a select field as you stated and then that value is being added to a regular text input field. If that is the case the following code should fix you up. If its going into another select field, then it'll need to be slightly different.

    jQuery(document).on('change', '#input_21_1', function(){
        jQuery('#input_21_3').val( this.val() );

redtundra - I think you meant this for line 3:

jQuery('#input_21_3').val( jQuery(this).val() );

Since .val() needs to be run on a jQuery object.

You can also pass $ into the first line so that you don't have to keep using 'jQuery':

... use $ here

You should also call your script from the footer. If you can, you should enqueue it properly:

Honestly, you could probably get away with passing this small snippet directly through with the form in an HTML field, unless Gravity Forms strips it out. If you do that, wrap your code in 'script' tags.

View Timeline