Skip to main content
stepheng54012748
Known Participant
January 14, 2018
Answered

If then question

  • January 14, 2018
  • 1 reply
  • 1075 views

If anyone can help with a scenario that I'm struggling with I would be eternally grateful.  I am learning how to write in Javascript but am very new to this.  I'll do my best to describe what is happening and how I'm trying to write the script.  Below is the breakdown:

Line "J10" is a sum of 5 lines.

Line "J13" is the sum of line "J10" and "J12" ONLY if Line "J10" is greater than 0.  If Line "J10" is a negative number then Line "J13" should return 0.  I've written the script so many different ways I think I've thoroughly confused myself.  At one point, I thought I solved it.  When I enter the number and it gave the result I was looking for on the positive side and then changed the number to a negative but the result from the previous script didn't change but stayed the same.  I want to be able to write the Javascript so if I test it with a positive result it gives the result I'm looking for and if I change the test number to a negative number that it switches to a 0. It's almost as if the script is unstable.  Any input on how to write this would be so greatly appreciated.  Thank you in advance.

Here is the latest that doesn't work.

var theField = this.getField("V1");

var theValue = theField.value;

var theField2 = this.getField("V2");

var theValue2 = theField.value2;

if (theValue > 0) {

    this.getField("J13").value= theValue2;

}

else {

     this.getField("J13").value= 0";  

}

This topic has been closed for replies.
Correct answer Bernd Alheit

Here is what I have so far:

var theField = this.getField("J5");

var theValue = theField.value;

var theField2 = this.getField("J6");

var theValue2 = theField2.value;

var theField3 = this.getField("J7");

var theValue3 = theField3.value;

var theField4 = this.getField("J8");

var theValue4 = theField4.value;

var theField5 = this.getField("J9");

var theValue5 = theField5.value;

var theField6 = this.getField("J11");

var theValue6 = theField6.value;

var theField7 = this.getField("J12");

var theValue7 = theField7.value;

if (+theValue <= 0) {

    event.value = (+theValue + +theValue2 + +theValue3 + +theValue4 + +theValue5);

}

else {

     event.value > (+theValue + +theValue2 + +theValue3 + +theValue4 + +theValue5 + +theValue6 + +theValue7);  

}

else {

     this.getField("J13").value="";  

}


Following line makes no sense:

event.value > (+theValue + +theValue2 + +theValue3 + +theValue4 + +theValue5 + +theValue6 + +theValue7); 

You can't use 2 else

You must use something like this:

if (...) {

} else if ( ... ) {

} else {

}

1 reply

Bernd Alheit
Community Expert
Community Expert
January 14, 2018

A field has no property with the name 'value2'.

stepheng54012748
Known Participant
January 14, 2018

Thank you for the response.  I understood that I'm getting that error.  Any suggestions what I can write to eliminate the error and get the result I'm looking for?

try67
Community Expert
Community Expert
January 14, 2018

Change that line to:

var theValue2 = theField2.value;