0

Having an unpredicted outcome using the && logical operator. If I link more than 2 expressions, the if clause fails. Is there some limit to the number of expressions that can be concatenated using &&?

 if (tTellerProN.checked && tCareProN.checked && tSalesProN.checked) { $(flListEmpty).empty(); $(flListEmpty).append($('<option></option>').val(0).html("Select Role")); $('.fl_list1 .list4').each(function (index) { $(flListEmpty).append($('<option> </option>').val(index).html($(this).text())); }) } 
4
  • Retagged because && belongs to javascript, not jQuery Commented Sep 29, 2011 at 17:00
  • What do you mean by "fails"? Do you mean evaluates to false? Commented Sep 29, 2011 at 17:00
  • use braces: ( and ) , to group && operations. Commented Sep 29, 2011 at 17:00
  • @c69 Good in practice but excess clutter if they are simple boolean values as in this situation. If it was something like (x + y == 2) && (y + z == 6) then I would agree. Commented Sep 29, 2011 at 21:06

3 Answers 3

4

&& is not a jQuery operator, it is Javascript. jQuery is a library that builds on Javascript.

I'm not sure what the ** is in your IF statment but this code works:

var x = true; var y = true; var z = true; alert(x && y && z); // true alert(x && y && !z); // false 

I would alert the values of your 3 .checked parameters and make sure they are being set as you expected.

Sign up to request clarification or add additional context in comments.

Comments

2

No, there is no limit. Your expression requires that all three checked values are true, otherwise it will return false. One of them must be false (or not true), that's why your if is failing.

For the record: && is part of the javascript language, not the jQuery library.

Comments

2

No, there is no limit.

However looking at your code (what little there is of it and with such descriptive variable names used), I would venture a guess that you actually mean ||, not &&.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.