Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using && and || problem 1

Status
Not open for further replies.

craigey

Technical User
Apr 18, 2002
510
GB
Hi guys,

I'm not too good when it comes to javascript & have run into a problem with a line of code.

The original line is:
Code:
if(f.value=='' && f.id!='email'){cf_adderr(f)}
which I thought would be relatively straightforward to add some additional validation too, such as:
Code:
if(f.value=='' && f.id!='email' ) || (f.value='Write Your Message Here...' && f.id!='email'){cf_adderr(f)}

For some reason this doesn't work & produces the word false into my e-mail form field!! I thought that the "||" was an or operater not an "&&".

Can anyone pleaase shed some light.

Thanks
 
You're close. You need to have brackets around the whole lot, and use double-equals (==) rather than single equals (=) when testing for equality:

Code:
if ((f.value=='' && f.id!='email' ) || (f.value == 'Write Your Message Here...' && f.id!='email')) {
   cf_adderr(f);
}

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Darn. I knew about the "==" as well, don't know why I couldn't see it! I'm sure I also tried with the brackets. Oh well.

I tested your line & still didn't get the results I was expecting. But then I checked the rest of the code properly, I realised the "write Your Message Here..." was actually in a textarea & not a text box, so I was checking the wrong field!!

Never Mind sorted it out now.

Thanks for your Help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top