Solved

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

Posted on 2015-01-08
7
144 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

776 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