Click to See Complete Forum and Search --> : How to write AND
geuis
03-25-2003, 01:48 PM
I need to have an IF statement check 2 things to see if they are true. I tried using && for the AND conditional, but apparently this is not the way to do it. I've included my code below. Thanks for any help.
if (FrontPage_Form1.Billing_OK.checked == true && FrontPage_From1.billing_agent.value == "")
{
alert("Its TRUE!");
return (false);
}
Phil Karras
03-25-2003, 01:52 PM
Since you're not testing a conditiion you really want the values to be ANDed and test the result, try only one &.
havik
03-25-2003, 03:12 PM
The problem could be in the way your referencing the form.
It should be of the form:
document.formname.sectionname.attribute
try:
if((document.FrontPage_Form1.Billing_OK.checked == true) && (document.FrontPage_From1.billing_agent.value == ""))
{
alert("Its TRUE!");
return (false);
}
havik
Phil Karras
03-26-2003, 01:46 PM
Both & or && should work, for different reasons. The reason I gave before is why using just & should work.
So, if you're having problems then there's something else worng.
havik has a good point but I'd go one step lower and try testing the way you're doing these things. For havik's example test it like this:
alert(document.FrontPage_Form1.Billing_OK.checked);
alert(document.FrontPage_From1.billing_agent.value);
jeffmott
03-26-2003, 01:59 PM
Phil Karras
No guys do it my way and simply AND the two together to get ONE result to test in the if statement, it works just fine!
The IF statement expects a condition that evaluates to logical true or false. Thus, the logical operators should be used. NOT bitwise operators. To mix the two because one conincidendly worked in place of the other is a bad programming practice. And using the correct notation would certainly not be an error. I agree with havik, the problem probably lies in how the form is referenced.
Phil Karras
03-26-2003, 02:24 PM
Not ture you can use either inside the if and it's done all the time.
However, if you look at my re-writing of the post you responded to you'll see that the statement you responded to is no longer there.
Also, that's not the problem anyway. See my advice on finding the real problem.