Solved

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

Posted on 2015-01-08
7
139 Views
Last Modified: 2015-01-08
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

0
Comment
Question by:PBLack
  • 4
  • 2
7 Comments
 
LVL 19

Expert Comment

by:Rikin Shah
ID: 40539639
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

0
 

Author Comment

by:PBLack
ID: 40539640
Just learning dude. I will try and get right back.
0
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 250 total points
ID: 40539641
Hi,
the error is grom the 4th line
if (cRtn = ...
should be
if (cRtn ==

as you currently set / assign the value.
Hth
Rainer
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 19

Assisted Solution

by:Rikin Shah
Rikin Shah earned 250 total points
ID: 40539642
Hi,

Also, I just noticed... You have not checked for any condition here.

if (cRtn = "4. N/A") should be replaced with if (cRtn == "4. N/A").

Single equals sign will do the assignment.
0
 

Author Comment

by:PBLack
ID: 40539643
Not working. It is still returning a value of N/A no matter what I choose from the popup menu.
0
 

Author Comment

by:PBLack
ID: 40539644
Opps never saw the other comments before that last comment from me. Hold on while I try
0
 

Author Comment

by:PBLack
ID: 40539646
Works perfectly. Thanks guys.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jQuery Parallax 1 38
Recordset containing single quotes 8 23
is this a cms? 8 35
Angular - disable input field on page load 4 14
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now