Checkform - Checking 2 fields
Hi
Firstly apologies for this question as I am sure it is really basic, however I just can't get my simple bit of code to do what I want.
I have a HTML form that I validate the entries with a bit of Java. All works perfectly until I try and check 2 fields using an AND operator (&&).
Code Java:
if (form.show.value =="Yes" && form.weeks.value == "elephant") {
alert( "Please enter the number of weeks that the booking will run" );
form.weeks.focus();
return false ;
}
It works if I use an OR operator (||) and works if I check either field singular. From the example I've seen on the net, the syntax looks ok...I've tried with brackets in different places, one & rather than &&, even tried a sub IF.
No point in pointing out that I'm very new to Java...
Many thanks in advance.
Chris
Re: Checkform - Checking 2 fields
Do not use == to compare objects as this compares references and not contents. Use the equals method instead.
Re: Checkform - Checking 2 fields
Quote:
Originally Posted by
Junky
Do not use == to compare objects as this compares references and not contents. Use the equals method instead.
Code Java:
if (form.show.value.equals("Yes") && form.weeks.value.equals("elephant")) {
Is this Java or JavaScript?