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.
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
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 = "";
...
Copy link to clipboard
Copied
What field names does you use?
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)
Copy link to clipboard
Copied
EDIT: I meant ROWS, not Columns!
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 = "";
...
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!
Copy link to clipboard
Copied
Check the Javascript console for errors.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
I FIXED IT!
i changed it from:
for (var i = 40; I >= idNumber; i--) {
to:
for (var i = 40; i => idNumber; i--) {
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--) {
Copy link to clipboard
Copied
@try67 @Bernd Alheit
I've moved this discussion to a new post because it seems to be a bit complicated.
Copy link to clipboard
Copied
So you want to delete the values in the first row?
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.
Copy link to clipboard
Copied
Yes, I understood. But that means the values in the first row will be deleted...