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

Posted on 2015-01-08
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.



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"
this.getField("PreTxt1").value = cRtn.substring(0,2)}

Open in new window

Question by:PBLack
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
LVL 19

Expert Comment

by:Rikin Shah
ID: 40539639

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


Author Comment

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

Accepted Solution

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

as you currently set / assign the value.
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

LVL 19

Assisted Solution

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

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.

Author Comment

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

Author Comment

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

Author Comment

ID: 40539646
Works perfectly. Thanks guys.

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

688 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