Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Making a Delete button For a form Via JAVASCRIPT

Participant ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

Hello,

I am trying to create buttons for corresponding fields that when clicked will remove the fields and replace the fields with the fields below.

Screen Shot 2021-04-16 at 9.05.37 am.png

I have placed this javascript in a button under "run a javascript" when "mouse up"

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

 

 I have done some tests and it seems that the problem is with thee "i" variable
can someone please help me with this problem

Thank you all kindly in advance!

-Flynn

TOPICS
Create PDFs, Edit and convert PDFs, General troubleshooting, How to, JavaScript, PDF forms

Views

2.2K

Likes

Translate

Translate

Report

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

correct answers 1 Correct answer

Adobe Community Professional , Apr 16, 2021 Apr 16, 2021
Something like this: var idNumber = parseInt(event.target.name.replace("Delete", "")); for (var i = idNumber; i < 40; i++) { this.getField("ID" + i).value = this.getField("ID" + (i + 1)).value; .. } var i = 40; this.getField("ID" + i).value = ""; ...

Likes

Translate

Translate
Adobe Community Professional ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

What field names does you use?

Likes

Translate

Translate

Report

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 ,
Apr 16, 2021 Apr 16, 2021

Copy link to clipboard

Copied

@Bernd Alheit 
The field names are a word plus a number that ranges from 1- 40. so the first columns all the words are
"ID1", "Desc1", "No1", "Unit1", "Price1" "Total1", 
and at the last column the fields are 

"ID40", "Desc40", "No40", "Unit40", "Price40" "Total40", 
The corresponding Button is labelled "Delete"+(1-40)

Likes

Translate

Translate

Report

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 ,
Apr 16, 2021 Apr 16, 2021

Copy link to clipboard

Copied

@Bernd Alheit 

EDIT: I meant ROWS, not Columns!

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Apr 16, 2021 Apr 16, 2021

Copy link to clipboard

Copied

Something like this:

var idNumber = parseInt(event.target.name.replace("Delete", ""));
for (var i = idNumber; i < 40; i++) {
  this.getField("ID" + i).value = this.getField("ID" + (i + 1)).value;
  ..
}
var i = 40;
this.getField("ID" + i).value = "";
...

Likes

Translate

Translate

Report

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 ,
Apr 29, 2021 Apr 29, 2021

Copy link to clipboard

Copied

Hey @Bernd Alheit  That works perfetly!

Could you help out with this code? its the same as the one you posted but is used for adding an empty field.

At this moment it seems to be doing nothing.

  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;
  }
  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 ="";

Thank you again! 

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Apr 29, 2021 Apr 29, 2021

Copy link to clipboard

Copied

Check the Javascript console for errors.

Likes

Translate

Translate

Report

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 ,
Apr 29, 2021 Apr 29, 2021

Copy link to clipboard

Copied

@Bernd Alheit 

I fixed the problem but now there is another problem.

 

Now it just duplicates the first thing that has a value in the field below it.

);

no error code in terminal

 

Likes

Translate

Translate

Report

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 ,
Apr 30, 2021 Apr 30, 2021

Copy link to clipboard

Copied

@Bernd Alheit 

I FIXED IT!

i changed it from:

for (var i = 40; I >= idNumber; i--) {

to:

for (var i = 40; i => idNumber; i--) {

 

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Apr 30, 2021 Apr 30, 2021

Copy link to clipboard

Copied

No, you didn't... Actually, you introduced a new error.

It should be:

for (var i = 40; i >= idNumber; i--) {

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

@try67 @Bernd Alheit 
I've moved this discussion to a new post because it seems to be a bit complicated.

https://community.adobe.com/t5/acrobat/making-an-add-empty-column-button-javascript/m-p/12009256#M31...

 

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Apr 16, 2021 Apr 16, 2021

Copy link to clipboard

Copied

So you want to delete the values in the first row?

Likes

Translate

Translate

Report

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 ,
Apr 16, 2021 Apr 16, 2021

Copy link to clipboard

Copied

@try67 
I want to replace the field with the field below it (Like in the poorly drawn picture).

The goal is to have a button next to every row so that when pressed all of the fields will move up into the field before it. It replaces the values with the fields below it and then the fields under that will be replaced and so on.

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Apr 16, 2021 Apr 16, 2021

Copy link to clipboard

Copied

Yes, I understood. But that means the values in the first row will be deleted...

Likes

Translate

Translate

Report

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