Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

javascripts to copy multiple text fields and paste to other text fields with buttons

New Here ,
Apr 26, 2023 Apr 26, 2023

I am looking for a javascript to copy a row of text fields with a button and then paste that into other text fields with a different button.  I was thinking of having 2 buttons at the end of the row, labeled C (for copy) and P (for paste). I would like the C button to copy all the text fields in that row and then click on the P button and paste the text value into that respective row. I just have no clue what to put for the javascripts. 

 

Below are two images. The first image shows what the first 3 rows would look like if they were filled out by users and the second image shows all the fields on the page. I didn't add the buttons at the end of each row yet because I wanted to figure out the scripts first before making a bunch of buttons. 

 

If anyone has any ideas for javascripts, I'm all ears. Thank you!

Personnel Page.PNGPersonnel Page Prepare Form.PNG

TOPICS
JavaScript , PDF forms
2.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Apr 26, 2023 Apr 26, 2023

Create four variables in Document level, like this:

var c1 = "";
var c2 = "";
var c3 = "";
var c4 = "";

To create document level script, select 'Prepare form' tool, then click on 'More' and select 'Document JavaScripts' (or press CTRL+D), enter name for the script and click 'Add', now delete everything from the window that pop up and paste variables inside, then press 'Ok'.

 

Now in each 'copy' button, use this:

c1 = this.getField("Agent Name.0").valueAsString;
c2 = this.getField("Call Sign.0").valueAsString;
c3 = this.getField("Personnel Vehicle.0").valueAsString;
c4 = this.getField("Assignment.0").valueAsString;

Just change row number in each button from 0 to 1,2,3...etc.

 

Now in each 'paste' button use this:

this.getField("Agent Name.0").value = c1;
this.getField("Call Sign.0").value = c2;
this.getField("Personnel Vehicle.0").value = c3;
this.getField("Assignment.0").value = c4;

Again change row number in each button with that button row 0 to 1,2,3...etc.

 

Here is a sample file of how it works:

https://drive.google.com/file/d/1Qr6wSTVKeJqcMSfdkN5SJjlraoLPAVvl/view?usp=share_link 

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 26, 2023 Apr 26, 2023

At copy store the values in variables. At paste use the values of the variables.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 26, 2023 Apr 26, 2023

Create four variables in Document level, like this:

var c1 = "";
var c2 = "";
var c3 = "";
var c4 = "";

To create document level script, select 'Prepare form' tool, then click on 'More' and select 'Document JavaScripts' (or press CTRL+D), enter name for the script and click 'Add', now delete everything from the window that pop up and paste variables inside, then press 'Ok'.

 

Now in each 'copy' button, use this:

c1 = this.getField("Agent Name.0").valueAsString;
c2 = this.getField("Call Sign.0").valueAsString;
c3 = this.getField("Personnel Vehicle.0").valueAsString;
c4 = this.getField("Assignment.0").valueAsString;

Just change row number in each button from 0 to 1,2,3...etc.

 

Now in each 'paste' button use this:

this.getField("Agent Name.0").value = c1;
this.getField("Call Sign.0").value = c2;
this.getField("Personnel Vehicle.0").value = c3;
this.getField("Assignment.0").value = c4;

Again change row number in each button with that button row 0 to 1,2,3...etc.

 

Here is a sample file of how it works:

https://drive.google.com/file/d/1Qr6wSTVKeJqcMSfdkN5SJjlraoLPAVvl/view?usp=share_link 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 27, 2023 Apr 27, 2023

May be better to use 2 functions with the row number as parameter.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 27, 2023 Apr 27, 2023
LATEST

Thank you so much! This worked perfectly!! 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 27, 2023 Apr 27, 2023

JS can't copy and paste fields. It can read (some of) the properties of a field, and then create a new field with those same properties, under a new location and with a new name, though.

In doing so you will lose all Actions associated with the original field, such as Format, Validate, Calculate, Mouse Up, etc., since those can't be read by the script.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines