Link to home
Start Free TrialLog in
Avatar of Todd MacPherson
Todd MacPhersonFlag for Canada

asked on

My if else statement is not working. Please help me fix it.

Hi Experts

I am a complete noob to javascript but I have been tinkering with it and trying to refine a popup menu script. Please look at the else if statement at the bottom. No matter what I select from the popup menu the value that is returned is always 'N/A' Please help me fix this.

Thanks

PBLack

var aHazard = ["Severity and Probability",["1. Imminent Danger","1A Probable","1B Reasonably Probable","1C Remote","1D Extremely Remote"],["2. Serious","2A Probable","2B Reasonably Probable","2C Remote","2D Extremely Remote"],["3. Minor","3A Probable","3B Reasonably Probable","3C Remote","3D Extremely Remote"],"4. N/A"];
var cRtn = app.popUpMenu(aHazard);

if(cRtn != null)
if(cRtn = "4. N/A") {
this.getField("PreTxt1").value = "N/A"
}else{
this.getField("PreTxt1").value = cRtn.substring(0,2)}

Open in new window

Avatar of Rikin Shah
Rikin Shah
Flag of India image

Hi,

Why dont you indent and give proper parenthesis?

try this-
if (cRtn != null) {
    if (cRtn = "4. N/A") {
        this.getField("PreTxt1").value = "N/A";
    } else {
        this.getField("PreTxt1").value = cRtn.substring(0, 2);
    }
}

Open in new window

Avatar of Todd MacPherson

ASKER

Just learning dude. I will try and get right back.
ASKER CERTIFIED SOLUTION
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Not working. It is still returning a value of N/A no matter what I choose from the popup menu.
Opps never saw the other comments before that last comment from me. Hold on while I try
Works perfectly. Thanks guys.