Skip to main content
davidm76220796
Known Participant
November 8, 2016
Answered

Conditional AND making Background Color change

  • November 8, 2016
  • 1 reply
  • 1193 views

First of all it really sucks being ignorant.  BUT, I am really grateful for the help offered here, so Thank You!!

I have created two Document Javascripts with an array of field names. 

Here is one...

function AddGPM()

{

    // Set up an array of field names

    var aNames = ["N36", "N37", "N38", "N39",

    "N40", "N41", "N42", "N43",

    "N44", "N45", "N46", "N47",

    "N48", "N49", "N50", "N51",

    "N52", "N53", "N54", "N55"];

    // Set up an object that will be returned

    var oValsGPM = {};

    // Loop through the field names and add name/value pairs to the object

    for (var i = 0; i < aNames.length; i += 1) {

        oValsGPM[aNames] = getField(aNames).value;

    }

    return oValsGPM;

}

Here is the other...

function AddPressure() {

    // Set up an array of field names

    var aNames = ["Red10", "Red20", "Red30", "Red40",

    "Brown10", "Brown20", "Brown30", "Brown40",

    "Grey10", "Grey20", "Grey30", "Grey40",

    "White10", "White20", "White30", "White40",

    "Blue10", "Blue20", "Blue30", "Blue40"];

// Set up an object that will be returned

    var oValsPressure = {};

    // Loop through the field names and add name/value pairs to the object

    for (var i = 0; i < aNames.length; i += 1) {

        oValsPressure[aNames] = getField(aNames).value;

    }

    return oValsPressure;

}

I am trying to change the background color of the field depending upon the value being greater or = to a value AND less than another value  AND

being dependent upon a different field being greater or = to yet another field.

var oVP=AddPressure();

var oVG=AddGPM();

var P28=this.getField ("P28").value;

var L30=this.getField("L30").value;

if(P28>=(oVG["N36"])

AND

(oVG["N37]))

AND

(oVP["Red10"]>=("L30")){

event.target.fillColor=color.yellow;

return;

}

I keep getting syntaxerror messages.

Where am I messing up?

This topic has been closed for replies.
Correct answer try67

The form I created has field L30 set as a number field.  Is the way I am pulling it into this condition messing up the number?

(I am sorry I am so ignorant, I am not understanding why the number is not coming over.  Thanks for your patience.)


OK, I see what happened. Just remove the quotes around "L30" and it should work.

1 reply

try67
Community Expert
Community Expert
November 8, 2016

Replace AND with && ...

However, this kind of condition doesn't make sense: oVP["Red10"]>=("L30")

You're comparing a number to a string, it seems. That won't work.

On Tue, Nov 8, 2016 at 5:42 PM, davidm76220796 <forums_noreply@adobe.com>

davidm76220796
Known Participant
November 8, 2016

Can I CAST L30 as a number ?

try67
Community Expert
Community Expert
November 8, 2016

No, because it's not a number. What would be the result of doing that, anyway?