?
Solved

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

Posted on 2015-01-08
7
Medium Priority
?
150 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 19

Assisted Solution

by:Rikin Shah
Rikin Shah earned 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…
Suggested Courses

765 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