File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes if cases and function call Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "if cases and function call" Watch "if cases and function call" New topic

if cases and function call

Michael Huber
Ranch Hand

Joined: Aug 20, 2004
Posts: 43
I have a quick one here, I'm using a function and I'm basically using it different time for different cases.

function MoveNames(one, two, three, four){

if(one){alert("here at one");}

if(one && two){alert("here at one and two");}

if(three && two){alert("here at three and two");}

problem is when I call the function with different parameters it gets caught in the case that its not supposed to be in.

MoveNames('one','two', '', '');
//this alerts "here at one" followed by "here at one and two"

anyway around this???
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852

I don't see the problem. You are testing for the existence of the parameters and it's giving you the expected results.

Perhaps it'd be best if you tell us what exactly you are trying to do, and to use the UBB code tags to make your code more presentable.

[Asking smart questions] [About Bear] [Books by Bear]
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
It is true in both cases, hence why you are seeing two alerts.

Use "else if" statements....and change the order of the checks.

Those two hints should help you out.

I agree. Here's the link:
subject: if cases and function call
It's not a secret anymore!