PDA

View Full Version : If (field1 equals "this") AND (field2 equals "that")...


IronMonkey
05-27-2003, 06:52 PM
Hi,

I'm trying to figure out how to validate a form with the following method:


If (field1 equals "this") AND (field2 equals "that")
alert("That combination is not allowed.")


So far, this is what I've come up with:


if (document.form.field1.value == "something" || document.form.field2.value == "another_something")

{ alert("That combination is not allowed...")
return false; }


However, the alert comes up even if just one of the fields equals the stated value! So, I guess that the || is basically an OR statement. What about the AND statement?

Anyone have any ideas?

Thanks.

Graeme Hackston
05-27-2003, 06:59 PM
&&

IronMonkey
05-27-2003, 07:29 PM
Cheers Graeme :thumbsup:

I had already tried just the & on it's own! :rolleyes:

Graeme Hackston
05-27-2003, 07:35 PM
This should help

http://www.devguru.com/Technologies/ecmascript/quickref/javascript_index.html

IronMonkey
05-27-2003, 07:46 PM
Thanks for the reference :thumbsup: