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

Adding more values to a event.value

Participant ,
Nov 15, 2023 Nov 15, 2023

Hi. I have a really long script that gives me a value.  I want to apply a different script to add the values of 2 more fields to the value.

 

 

var a1 = this.getField("o1i").value;
var a2 = this.getField("o1iother").value;
var a3 = this.getField("o1iother2").value;
var b1 = this.getField("o2i").value;
var b2 = this.getField("o2iother").value;
var c1 = this.getField("o3i").value;
var c2 = this.getField("o3iother").value;
var d1 = this.getField("o4i").value;
var d2 = this.getField("o4iother").value;
var e1 = this.getField("o5i").value;
var e2 = this.getField("o5iother").value;
var e3 = this.getField("o5in").value;
var f1 = this.getField("o6i").value;
var f2 = this.getField("o6iother").value;
var insure = this.getField("ins.1").value;
var location = this.getField("location").value;
var mins = this.getField("mins1").value;
var units = mins/15;
var runits = Math.round(units);


if(insure == "Cs"){
  event.value = Math.min(898.50,runits*a1+a2+a3).toFixed(2);
}

else if(insure == "Dq"){
  event.value = Math.min(960.06,runits*b1+b2).toFixed(2);
}

else if(insure == "En"){
  event.value = Math.min(818.72,runits*c1+c2-4.05).toFixed(2);
}

else if(insure == "G"){
  event.value = Math.min(697.56,runits*d1+d2).toFixed(2);
}

else if(insure == "Sp" && location == "H"){
  event.value = e3.toFixed(2);
}
else if(insure == "Sp" && location == "P"){
  event.value = e3.toFixed(2);
}
else if(insure == "Sp" && location == "Y"){
  event.value = e3.toFixed(2);
}
else{
  event.value = e1.toFixed(2);
}


if (mins==""){
  event.value = 0;
}

if (insure =="--"){
  event.value = 0;
}

 

How do I add more values to the answer from the above script using the script below?

 

var row = this.getField("row").value;
var row2 = this.getField(“row2").value;
var im = this.getField(“im").value;
var im2 = this.getField(“im2").value;


If (row == 1){
event.value = event.value + rowmath + im
}
||
If (row2 == 1){
event.value = event.value + rowmath2 + im2
}

 

 

TOPICS
JavaScript , PDF , PDF forms
2.9K
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 ,
Nov 15, 2023 Nov 15, 2023

You can add variables to your variables list.

Conditions (it's 'if' not 'If') depends on when do you want them to trigger?

You need to be careful of your conditions order.

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 ,
Nov 16, 2023 Nov 16, 2023

You have a lot of errors in your code that you need to sort out first.

For example:

- It's "if", not "If".

- You may only use straight quotes (" "), not curly ones ( “ ” ).

 

To answer your question, though, you can add additional values to any string by using the + or += operators, like this:

 

var a = "ABC";

a+="DEF";

app.alert(a); // will show "ABCDEF"

 

 

var a = "ABC";

a="DEF" + a;

app.alert(a); // will show "DEFABC"

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 ,
Nov 16, 2023 Nov 16, 2023

Thank you!  I think I understand that part. 

 

var row1 = this.getField("row1").value;
var row2 = this.getField("row2").value;
var row3 = this.getField("row3").value;
var row4 = this.getField("row4").value;
var row5 = this.getField("row5").value;
var row6 = this.getField("row6").value;
var im1 = this.getField("im1").value;
var im2 = this.getField("im2").value;
var im3 = this.getField("im3").value;
var im4 = this.getField("im4").value;
var im5 = this.getField("im5").value;
var im6 = this.getField("im6").value;

var rowt = event.value 
rowt = rowt + im + row

if (row1 == 1){
event.value = rowt;
}
if (row2 == 1){
event.value = rowt;
}
if (row3 == 1){
event.value = rowt;
}
if (row4 == 1){
event.value = rowt;
}
if (row5 == 1){
event.value = rowt;
}
if (row6 == 1){
event.value = rowt;
}

 

 Is there a way to simplify and complete it with maybe for( var i=1; i<=6; i++)?

 

var rowt = event.value;
rowt = rowt+i + im+i + row+i;

 

I know this is wrong, but it is the only way I can explain what I am looking to do.

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 ,
Nov 16, 2023 Nov 16, 2023

This does not make sense. If you do it like that the value of the field will keep getting longer and longer each time, ad infinitum. What exactly are you trying to achieve?

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 ,
Nov 16, 2023 Nov 16, 2023

I have 15 rows of date and each row has a calculated value.  I would like to possibly add 2 more values (from a different 6 rows of data) to any given row if a certain condition applies (row # 1-15 entered).  I've attached an image that may 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 ,
Nov 17, 2023 Nov 17, 2023

OK, now it's more clear. You have to do it all in the calculation script of the total fields on the right.

What's their calculation currently?

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 ,
Nov 17, 2023 Nov 17, 2023

It is calculated using this script

var a1 = this.getField("o1i").value;
var a2 = this.getField("o1iother").value;
var a3 = this.getField("o1iother2").value;
var b1 = this.getField("o2i").value;
var b2 = this.getField("o2iother").value;
var c1 = this.getField("o3i").value;
var c2 = this.getField("o3iother").value;
var d1 = this.getField("o4i").value;
var d2 = this.getField("o4iother").value;
var e1 = this.getField("o5i").value;
var e2 = this.getField("o5iother").value;
var e3 = this.getField("o5in").value;
var f1 = this.getField("o6i").value;
var f2 = this.getField("o6iother").value;
var insure = this.getField("ins.1").value;
var location = this.getField("location").value;
var mins = this.getField("mins1").value;
var units = mins/15;
var runits = Math.round(units);


if(insure == "Cs"){
  event.value = Math.min(898.50,runits*a1+a2+a3).toFixed(2);
}

else if(insure == "Dq"){
  event.value = Math.min(960.06,runits*b1+b2).toFixed(2);
}

else if(insure == "En"){
  event.value = Math.min(818.72,runits*c1+c2-4.05).toFixed(2);
}

else if(insure == "G"){
  event.value = Math.min(697.56,runits*d1+d2).toFixed(2);
}

else if(insure == "Sp" && location == "H"){
  event.value = e3.toFixed(2);
}
else if(insure == "Sp" && location == "P"){
  event.value = e3.toFixed(2);
}
else if(insure == "Sp" && location == "Y"){
  event.value = e3.toFixed(2);
}
else{
  event.value = e1.toFixed(2);
}


if (mins==""){
  event.value = 0;
}

if (insure =="--"){
  event.value = 0;
}
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 ,
Nov 16, 2023 Nov 16, 2023
 
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 ,
Nov 17, 2023 Nov 17, 2023

What are the names of the Amount fields on the left?

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 ,
Nov 17, 2023 Nov 17, 2023

Another image is attached. The column with rowmath(1-6) are hidden fields used for calculation purposes only.  The calculation for those are from the script: 

 

if (this.getField("imo1").value != "Off"){
event.value = this.getField("ri" + row).value * -1;
}
else {
event.value = 0;
}

 

So, the final calcuation would be:

Original Amount + rowmath + Amount 1 + Amount 2 = New Amount

I made the number for rowmath negative so that it is subtracting that amount from the original amount.

 

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 ,
Nov 17, 2023 Nov 17, 2023

Try this code (for the field corresponding with "1"):

 

var a1 = this.getField("o1i").value;
var a2 = this.getField("o1iother").value;
var a3 = this.getField("o1iother2").value;
var b1 = this.getField("o2i").value;
var b2 = this.getField("o2iother").value;
var c1 = this.getField("o3i").value;
var c2 = this.getField("o3iother").value;
var d1 = this.getField("o4i").value;
var d2 = this.getField("o4iother").value;
var e1 = this.getField("o5i").value;
var e2 = this.getField("o5iother").value;
var e3 = this.getField("o5in").value;
var f1 = this.getField("o6i").value;
var f2 = this.getField("o6iother").value;
var insure = this.getField("ins.1").value;
var location = this.getField("location").value;
var mins = this.getField("mins1").value;
var units = mins / 15;
var runits = Math.round(units);

if (mins == "" || insure == "--") {
    total = 0;
} else {
    var total = 0;

    if (insure == "Cs") {
        total = Math.min(898.50, runits * a1 + a2 + a3);
    } else if (insure == "Dq") {
        total = Math.min(960.06, runits * b1 + b2);
    } else if (insure == "En") {
        total = Math.min(818.72, runits * c1 + c2 - 4.05);
    } else if (insure == "G") {
        total = Math.min(697.56, runits * d1 + d2);
    } else if (insure == "Sp" && location == "H") {
        total = e3;
    } else if (insure == "Sp" && location == "P") {
        total = e3;
    } else if (insure == "Sp" && location == "Y") {
        total = e3;
    } else {
        total = e1;
    }
	
	for (var i=1; i<=6; i++) {
		if (this.getField("row"+i).value=="1") {
			total+=Number(this.getField("imo"+i).valueAsString) + Number(this.getField("rx"+i).valueAsString) - Number(this.getField("rowmath"+i).valueAsString);
		}
	}
	event.value = total.toFixed(2);
}
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 ,
Nov 17, 2023 Nov 17, 2023

The total is incorrect.  I tested just the first part (without the row 1-6 calculation included).  It came out to 700.00 when it should be 150.39. 

This is the part of the script that equals 700.00:

 

 

else {
        total = e1;
    }

 

 

 

I get a popup error:

The value entered does not match the format of the field [ ri1 ]

  

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 ,
Nov 17, 2023 Nov 17, 2023
LATEST

I'll need to see the file itself to be able to help you further with this.

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