/    Sign up×
Community /Pin to ProfileBookmark

can i use OR (||) AND (&&) together ?

hi

i want to know if the following if statement is valid….

its not throwing an error, but is also not doing what i want it to do….

I want to check if : (Hotel OR Car) and Leg1 =”” ….. then do something…

var f = document.forms[0];
var i;

if(((f.Air1.options[f.Airl1.options.selectedIndex].text !==”Hotel”) || (f.Air1.options[f.Air1.options.selectedIndex].text !==”Car”)) && (f.Leg1.value==””)) {

return false;
}

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Mar 16.2009 — Yes, you can combine them any number of times. Another thing that doesn't matter is, you don't necessarily need all the brackets you have, I find the fewer that have to be used the better.if((f.Air1.options[f.Airl1.options.selectedIndex].text !=="Hotel" || f.Air1.options[f.Air1.options.selectedIndex].text !=="Car") && f.Leg1.value=="") {But that's just personal preference, just that you are aware that you don't necessarily need brackets (parentheses if you want to use the correct term) around everything. I would advise you always use it around the (x || y) because that makes it clear that it's && the result of that.
Copy linkTweet thisAlerts:
@stirnpanzerauthorMar 16.2009 — thanks ........ yes too many brackets.... now ok ....
×

Success!

Help @stirnpanzer spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...