Skip to main content
Participating Frequently
October 12, 2023
Answered

Custom Validation Script

  • October 12, 2023
  • 1 reply
  • 901 views

I am running a validation script on a calculated form field (called "% Trans"), and its behaving unexpectedly. If I get a value that is 80%, it does turn green. But then if I re-enter the numerator and denominator and get 70%, it will stay green until I put in another value that changes it. I can go back to 80% but then its red to reflect the previous 70% value...

 

First,  I am calculating the value of this field using the Javascript:

 

var numerator = this.getField("Power Output in Watts").value;
var denominator = this.getField("LH Power Output").value;

if (denominator == 0 || denominator == null) {event.value = "";}
else {event.value = (numerator / denominator).toFixed(4);;}

 

Second, I want change the fill color of the field depending on that calculated value, so I have this JavaScript in the custom validation:

 

var v = this.getField("% Trans").value;

if (v>.7649) {event.target.fillColor = color.green;}

if (v<.7650) {event.target.fillColor = color.red;}

 

I imagine its something to do with the validation script declaring the variable v and using the getField to assign its value... I think I should be able to cut out the whole variable declaration and just have some simple if statement so as soon as the box is over .7649 it turns green, but I am not familiar at all with the syntax and how I could express it.

 

Please help!

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

Replace

var v = this.getField("% Trans").value;

with

var v = event.value;

 

1 reply

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
October 12, 2023

Replace

var v = this.getField("% Trans").value;

with

var v = event.value;

 

Participating Frequently
October 12, 2023

Thank you so much, you are awesome!!!