Forms: use JS to change text colour
I am creating a grade sheet to report exam scores to students, and I'd like to simplify things using JS. Unfortunately, I have little knowledge of JS, and I've been sitting here trying to make it work for me. Alas, it's time to turn to the forum.
I'm stumped on this problem: I need the colour of the text to change based on the relationship between two fields.
1. Field 'Gr_Score' is the score earned by the student.
2. Field 'Gr_Points' is the number of points for that section of the exam.
If the ratio (i.e. the result of 'Gr_Score' divided by 'Gr_Points') is less than 60%, the text in 'Gr_Score' needs to appear red. If the ratio is greater than or equal to 60%, the text in 'Gr_Score' needs to appear green. (The text in 'Gr_Points' does not change colour.)
For example:
Gr_Score = 6.0
Gr_Points = 10
Ratio = 6/10 = 0.6
Gr_Score displays as green
Gr_Score = 5.9
Gr_Points = 10
Ratio = 5.9/10 = 0.59
Gr_Score displays as red
The code currently looks like this:
--
var s = this.getField("Gr_Score"); // retrieve value of 'Gr_Score'
var p = this.getField("Gr_Points"); // retrieve value of 'Gr_Points'
var v = s / p ; // find the ratio of the score to points
if (v>=0 && v<.6) {event.target.textColor = color.red;}
else event.target.textColor = ["RGB",0,.667,0];
--
Thanks for any help you can give!
