Skip to main content
drslrb
Known Participant
November 16, 2023
Question

Adding more values to a event.value

  • November 16, 2023
  • 2 replies
  • 2465 views

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
}

 

 

This topic has been closed for replies.

2 replies

try67
Community Expert
November 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"

drslrb
drslrbAuthor
Known Participant
November 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.

try67
Community Expert
November 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?

Nesa Nurani
Community Expert
November 16, 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.