aspose file tools*
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
Author

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.

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


anyway around this???
thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

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] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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.

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: if cases and function call