0

How do you write AND on an if condition in javascript? I want to have this code but it produces an error.

if(xmlDoc.selectSingleNode("//RentersInsuranceSetting/Row").getAttribute("ExcludeCorporateUnits")==1) AND (xmlDoc.selectSingleNode("//AllPeople/Row").getAttribute("BusinessCorporationBit")==1)
    {  
    confirmValidRentersInsurance.required = "noReq"
    confirmValidRentersInsurance.style.color = "blue"
    insuranceRequired = false   
    }

what is the operator for AND in javascript?

4

4 に答える 4

1

The logical "and" operator in JavaScript is &&.

Also here's a quick reference

于 2013-01-07T01:55:44.930 に答える
1

The && operator will do that. For example...

if (condition1 && condition2) 
{ // if 2 conditions are true, then execute this line... }
于 2013-01-07T01:56:53.497 に答える
1

You use the && operator.

You also need another set of parentheses, so that you get if ((...) && (...)) instead of if (...) && (...):

if ((xmlDoc.selectSingleNode("//RentersInsuranceSetting/Row").getAttribute("ExcludeCorporateUnits")==1) && (xmlDoc.selectSingleNode("//AllPeople/Row").getAttribute("BusinessCorporationBit")==1))

Or remove some parentheses to make it if (... && ...). As the == operator has higher precedence than the && operator, you don't need them:

if (xmlDoc.selectSingleNode("//RentersInsuranceSetting/Row").getAttribute("ExcludeCorporateUnits")==1 && xmlDoc.selectSingleNode("//AllPeople/Row").getAttribute("BusinessCorporationBit")==1)
于 2013-01-07T01:58:00.437 に答える
0
&&

See http://www.w3schools.com/js/js_comparisons.asp

Maybe look at these javascript tutorials on the above web site.

于 2013-01-07T01:56:51.987 に答える