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

Making an add 'empty column' button [JAVASCRIPT]

Participant ,
May 02, 2021 May 02, 2021

Hello,

I'm trying to make multiple buttons that when hit will pull the fields above It down until it hits the field where the button lies:

Screen Shot 2021-05-02 at 8.53.12 pm.pngexpand image

 Once all the fields move down then the value of the fields that are next to the button pressed will be changed to "".

 

I have tried to use the following code but it does not seem to work:

 

  var idNumber = parseInt(event.target.name.replace("Add", ""));
for (var i = 40; i >= idNumber; i--) {
    this.getField("ID" + i).value = this.getField("ID" + (i - 1)).value;
    this.getField("Desc" + i).value = this.getField("Desc" + (i - 1)).value;
    this.getField("No" + i).value = this.getField("No" + (i - 1)).value;
    this.getField("Unit" + i).value = this.getField("Unit" + (i - 1)).value;
    this.getField("Price" + i).value = this.getField("Price" + (i - 1)).value;
    this.getField("Total" + i).value = this.getField("Total" + (i - 1)).value;
}
    this.getField("ID" + idNumber).value = "";
    this.getField("Desc" + idNumber).value = "";
    this.getField("No" + idNumber).value = "";
    this.getField("Unit" + idNumber).value = "";
    this.getField("Price" + idNumber).value = "";
    this.getField("Total" + idNumber).value ="";

 

This code just replicates the first field that has a value to the fields under it one time.

 

 

Can someone please help me with this problem?

Thank you.

TOPICS
Create PDFs , Edit and convert PDFs , How to , JavaScript , PDF forms
3.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
Participant ,
May 03, 2021 May 03, 2021

I have successfully made this code which does what I have described. I was advised not to use "=>" but it seems to be the only way the script works );

var idNumber = parseInt(event.target.name.replace("Add", ""));
for( i = 40; i => idNumber; i-- ){
    this.getField("ID" + i).value = this.getField("ID" + (i - 1)).value;
    this.getField("Desc" + i).value = this.getField("Desc" + (i - 1)).value;
    this.getField("No" + i).value = this.getField("No" + (i - 1)).value;
    this.getField("Unit" + i).value = this.getField("Unit" + (i - 1)).value;
    this.getField("Price" + i).value = this.getField("Price" + (i - 1)).value;
    this.getField("Total" + i).value = this.getField("Total" + (i - 1)).value;
if (i === idNumber+1) { break; }
}
    this.getField("ID" + idNumber).value = "";
    this.getField("Desc" + idNumber).value = "";
    this.getField("No" + idNumber).value = "";
    this.getField("Unit" + idNumber).value = "";
    this.getField("Price" + idNumber).value = "";
    this.getField("Total" + idNumber).value = "";

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 ,
May 02, 2021 May 02, 2021

Empty column or empty row?

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
Participant ,
May 02, 2021 May 02, 2021

Row* sorry

@Bernd Alheit 

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 ,
May 02, 2021 May 02, 2021

Can you share the form?

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
Participant ,
May 03, 2021 May 03, 2021

@Bernd Alheit 

Thank you for your help!

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 ,
May 03, 2021 May 03, 2021

Use following to clear the row:

    var i = idNumber;
    this.getField("ID" + i).value = "";
    this.getField("Desc" + i).value = "";
    this.getField("No" + i).value = "";
    this.getField("Unit" + i).value = "";
    this.getField("Price" + i).value = "";
    this.getField("Total" + i).value = "";
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
Participant ,
May 03, 2021 May 03, 2021

@Bernd Alheit 
Thank you, but this still does not fix the issue. );

It still stops at the first field row that has a value.

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 ,
May 03, 2021 May 03, 2021

Check the Javascript console for errors.

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
Participant ,
May 03, 2021 May 03, 2021

@Bernd Alheit 
No errors showing. );

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 ,
May 03, 2021 May 03, 2021

Your script varies from row to row.

You can put the script in a function and use the function at the rows.

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
Participant ,
May 03, 2021 May 03, 2021

Sorry, @Bernd Alheit  I do not understand? how does the script vary? (besides the row number "idNumber").

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
Participant ,
May 03, 2021 May 03, 2021

I have successfully made this code which does what I have described. I was advised not to use "=>" but it seems to be the only way the script works );

var idNumber = parseInt(event.target.name.replace("Add", ""));
for( i = 40; i => idNumber; i-- ){
    this.getField("ID" + i).value = this.getField("ID" + (i - 1)).value;
    this.getField("Desc" + i).value = this.getField("Desc" + (i - 1)).value;
    this.getField("No" + i).value = this.getField("No" + (i - 1)).value;
    this.getField("Unit" + i).value = this.getField("Unit" + (i - 1)).value;
    this.getField("Price" + i).value = this.getField("Price" + (i - 1)).value;
    this.getField("Total" + i).value = this.getField("Total" + (i - 1)).value;
if (i === idNumber+1) { break; }
}
    this.getField("ID" + idNumber).value = "";
    this.getField("Desc" + idNumber).value = "";
    this.getField("No" + idNumber).value = "";
    this.getField("Unit" + idNumber).value = "";
    this.getField("Price" + idNumber).value = "";
    this.getField("Total" + idNumber).value = "";
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 ,
May 03, 2021 May 03, 2021

You doesn't use the same script at all buttons.

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
Participant ,
May 04, 2021 May 04, 2021

I had changed all the buttons, and it still didn't work

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 ,
May 04, 2021 May 04, 2021
LATEST

Use a function then you need change the script only once.

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