Skip to main content
Participant
December 5, 2017
Question

Help with javascript to calculate many fields

  • December 5, 2017
  • 3 replies
  • 469 views

Hello,

I need help with my java code. I got a form with 3 columns with 160 text fields in each column. They are named A1.0.0-A1.15.9, B1.0.0-B1.15.9, C1.0.0-C1.15.9.

What i want to do is take (value of) B1.x.x - C1.x.x and if the difference is more then 1.0 and less then 1.9 i want to give a message to controll that number.

So far i got this code:

(function calculate() { 

    var fieldNumber = event.target.name.replace("A", ""); 

    var v1 = +this.getField("B"+fieldNumber).value; 

    var v2 = +this.getField("C"+fieldNumber).value;

    var v3 = v1 - v2;

event.value = v3;     

})()

else if ((v3 >= 1.0) && (v3 <= 1.9)) {

app.alert = ("controll this");

}

else {

event.value = "";

})();

I get a syntex error on row 9, what did i miss? My idea is to call on this function in the calculate tab in the A.x.x column. Please help a novice thats trying to learn java

This topic has been closed for replies.

3 replies

Legend
December 5, 2017

Look at line 8. It starts with "else". Why?

try67
Community Expert
Community Expert
December 5, 2017

There are a lot of errors in your code. You have lines outside the function. You have an else if without a preceding if. You have a mismatched number of parentheses, etc.

Legend
December 5, 2017

The error is on the app.alert line. The = sign does not belong. = is used only to set one value to another, but you aren't changing app.alert.

Legend
December 5, 2017

Oh, and you have an "else" without an "if". When you've fixed this I think you will find the messages very annoying as there will be far too many of them.

Participant
December 5, 2017

Thank you. Yes i guess it can be annoying with alot of messages. I was thinking about highlighting the fields instead of message. Something like this:

(function calculate() {

    var fieldNumber = event.target.name.replace("A", "");

    var v1 = +this.getField("B"+fieldNumber).value;

    var v2 = +this.getField("C"+fieldNumber).value;

    var v3 = v1 - v2;

event.value = v3;    

}()

else if ((v3 >= 1.0) && (v3 <= 1.9)) {

    fillColor = color.red; 

    fillColor = color.red;

}

else if {

event.value = "";

})();

@try67 if you could please point out the errors you mentioned, that would help alot. Im just starting to learn java. i dont think i can use above code to fill/highlight cells, any ideas how to improve the code?