Copy link to clipboard
Copied
Hi All!
I am sort of a novice at Java and am needing to format field a number of fields based on a dropdown. I have been searching for days on a resolution but hacnet found what I need. I have this so far, but I am needing to only change the fill certain fields based on the dropdown option of yes or no. What I am wanting is If "Yes", only fields N1, SS1, D1, & In1 are highlighted and if "No", all fields are highlighted.
var newfillColor;
if (event.value=="Yes") newfillColor = color.yellow;
else if (event.value=="No") newfillColor = color.yellow;
else newfillColor = color.transparent;
event.target.newfillColor = newfillColor;
this.getField("N1").fillColor = newfillColor;
this.getField("SS1").fillColor = newfillColor;
this.getField("D1").fillColor = newfillColor;
this.getField("Pa1").fillColor = newfillColor;
this.getField("Ph1").fillColor = newfillColor;
this.getField("Em1").fillColor = newfillColor;
this.getField("C1").fillColor = newfillColor;
this.getField("Emp1").fillColor = newfillColor;
this.getField("EPla1").fillColor = newfillColor;
this.getField("In1").fillColor = newfillColor;
Would the below work?
var newfillColor;
if (event.value=="Yes") {
this.getField("N1").fillColor = newfillColor;
this.getField("SS1").fillColor = newfillColor;
this.getField("D1").fillColor = newfillColor
};
else if (event.value=="No") {
var newfillColor = color.yellow;
this.getField("N1").fillColor = newfillColor;
this.getField("SS1").fillColor = newfillColor;
this.getField("D1").fillColor = newfillColor;
this.getField("Pa1").fillColor = newfillColor;
this.getField("Ph1").fillColor = newfillColor;
this.getField("Em1").fillColor = newfillColor;
this.getField("C1").fillColor = newfillColor;
this.getField("Emp1").fillColor = newfillColor;
this.getField("EPla1").fillColor = newfillColor;
this.getField("In1").fillColor = newfillColor
};
else newfillColor = color.transparent;
event.target.newfillColor = newfillColor;
Copy link to clipboard
Copied
No, because you haven't defined the initial value of newfillColor. Also, you need to change the other fields back from yellow to transparent, in case the selection is changed.
I would do it like this:
var yesFields = ["N1", "SS1", "D1"];
var noFields = ["Pa1", "Ph1", "Em1", "C1", "Emp1", "EPla1", "In1"];
for (var i in yesFields) {
this.getField(yesFields[i]).fillColor = (event.value=="Yes") ? color.yellow : color.transparent;
}
for (var i in noFields) {
this.getField(noFields[i]).fillColor = (event.value=="No") ? color.yellow : color.transparent;
}
PS. For future reference, this is JavaScript, not Java. Similar names, but quite different languages...
Copy link to clipboard
Copied
Wait, I'm seeing now that you're coloring the Yes-fields in yellow even if No is selected... Is that correct? Then why not just leave them yellow all the time, or is there another option in the drop-down that you didn't mention?