Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Fix/imporove my jQuery script | Gravity Forms incrementation WordPress



I have this script running on my site in my functions.php

// For each GF list item, make the first column read-only and increment with +1
function gf_readonly() {
if (is_product()) {
<script type="text/javascript">
$(".gform_wrapper .gf-readonly .gfield_list_cell:first input").attr("readonly", "");
$(".gform_wrapper .gf-readonly .gfield_list_cell:first input").val( function(i, oldval) {return ++oldval;});


add_action('wp_footer', 'gf_readonly');

Specifically, I need help with this part

$(".gform_wrapper .gf-readonly .gfield_list_cell:first input").val( function(i, oldval) {return ++oldval;});

I am using this snippet [[LINK href=""]]Set Number of List Field Rows by Field Value | Gravity Wiz[[/LINK]] to automatically spawn a number of Field List rows depending on the value of another field in my form.

All works fine, expect that when I input, for example, "3" in my input field, the additionally added Field List items are not incremented with numbers.
Most likely because my jQuery script needs to be fired again somehow, I just don't know how.

See a video demo here, then it all makes more sense: [[LINK href=""]]Demo Video[[/LINK]]

Basically the newly added rows need to have "2" and "3", "4", "5", etc. inserted automatically when a number is specifed in the input field above the list field.

Answers (2)


Jayaram Y answers:

Hi Cruiseback,

I have done this in my test environment. Please check here:

Attached screenshot as well

cruiseback comments:

Hi Jayram,

Great, I copied your script from your source and it seems to work perfectly, money goes to you.



Reigel Gallarde answers:

I need to see the page... but here's a guess... add this..

var tr = jQuery(this).closest('tr');

cruiseback comments:

Hi Reigel,

The site is on my localhost right now, I can probably put it live somewhere later today.