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

Making a Delete button For a form Via JAVASCRIPT

Participant ,
Apr 15, 2021 Apr 15, 2021

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.pngexpand image

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
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
Community Expert ,
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 = "";
...

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

What field names does you use?

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

@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)

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

@Bernd Alheit 

EDIT: I meant ROWS, not Columns!

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 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 = "";
...
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 ,
Apr 29, 2021 Apr 29, 2021

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! 

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

@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

 

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

@Bernd Alheit 

I FIXED IT!

i changed it from:

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

to:

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

 

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

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

It should be:

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

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
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...

 

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

So you want to delete the values in the first 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 ,
Apr 16, 2021 Apr 16, 2021

@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.

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

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

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