Solved

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

Posted on 2015-01-08
7
138 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

747 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

10 Experts available now in Live!

Get 1:1 Help Now