• Skip to main content

Victor Font Consulting Group, LLC

The DEX Intranet Specialists

Call Us:

+1 919-604-5828

  • Home
  • Care Plans
    • Care Articles
    • Optional Subscriptions
  • Consultations
  • Products
    • Code Snippets
    • Public GitHub Repositories
    • Gist Snippets
    • Pastebin Snippets (Free)
    • Free Plugins
  • FAQs
  • Support
    • Graphic Design
  • Contact
    • Speakers
    • Portfolio
  • Resources
    • Free WordPress Video Training
    • Tutorials
    • Articles
    • Cybersecurity
    • EU Referral Network
You are here: Home / Code Snippet / FormidableForms: Copy Repeatable Field Val to Another

FormidableForms: Copy Repeatable Field Val to Another

By Victor M. Font Jr.
July 19, 20171 Comment

The Problem

A user asked the following question on the FormidableForms Community Forum:

I have a form in which I used the following script to copy text from one text field to another (lookup text field). It worked until now. But now that I have moved these two fields into a repeatable section, the script has stopped working.

The Solution

When you added the fields to the repeatable section, the field ID changed.

The first field on form is field_o8v4sw-0. When you add a row to a repeatable section, the field ids will incremented. So, if you 9 more rows, the field ids will be:

field_o8v4sw-0
field_o8v4sw-1
field_o8v4sw-2
field_o8v4sw-3
field_o8v4sw-4
field_o8v4sw-5
field_o8v4sw-6
field_o8v4sw-7
field_o8v4sw-8
field_o8v4sw-9

Counting always starts at 0. Instead of checking for each individual field to change, this can be done with a wild card.

$("[id^=field_o8v4sw]").on("change", function() { //source field key
var sourceField = $(this).val(); //source field key

In order to determine the destination field, you're going to have to do some string manipulation. So the first thing we have to do is get the actual ID of the target field.

var field_id = $(this).attr("id");

Next, we need to get the number at the end of the ID. This number will be the same as the destination field.

var index_number = field_id.substr(field_id.lastIndexOf("-")+1);

Now we can populate the destination field.

var destination_field = "#field_6qubt-" + index_number;
$(destination_field).val(sourceField);

Here is your new jQuery:

  • 10shares
  • Facebook4
  • Twitter0
  • Pinterest0
  • LinkedIn4
  • Print
  • SMS0

About Victor M. Font Jr.

Victor M. Font Jr. is an award winning author, entrepreneur, and Senior IT Executive. A Founding Board Member of the North Carolina Executive Roundtable, he has served on the Board of Advisors, of the North Carolina Technology Association, the International Institute of Business Analysis, Association of Information Technology Professionals, Toastmasters International, and the North Carolina Commission for Mental Health, Developmental Disabilities, and Substance Abuse Services. He is author of several books including The Ultimate Guide to the SDLC and Winning With WordPress Basics, and Cybersecurity.

Reader Interactions

VictorFont.com runs on the Genesis Framework

Genesis FrameworkThe Genesis Framework empowers you to quickly and easily build incredible websites with WordPress. Genesis provides the secure and search-engine-optimized foundation that takes WordPress to places you never thought it could go.

Check out the incredible features and the selection of designs. It's that simple—start using Genesis now!

Click here to download The Genesis Guide for Absolute Beginners (PDF - 1.4 MB)

Leave a Reply Cancel reply

Your email address and website will not be published. Required fields are marked *
Posting a comment means that you agree with and accept our Comment & Product Review Policy

Comments

  1. Eric Desgranges

    October 29, 2017 at 7:47 am

    Thank you for this enlightening post. I found out though that jQuery wasn’t able to trigger changes for indexes greater or equal to 1.

    The solution I found (after reading https://stackoverflow.com/questions/7244935/how-to-apply-jquery-change-for-input-elements-that-have-id-starting-with-a-pa) :

    $(“[id^=field_o8v4sw-]”).live(“change”, function() {

    Reply

Call: +1 919-604-5828

Send us an E-mail

Accessibility Statement | Affiliate Marketing Disclosure | Capability Statement

Cookie Policy | Comment & Product Review Policy | Privacy Policy | Site Map | Terms & Conditions

Copyright © 2003–2023 Victor M. Font Jr.

Return to top of page