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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quick easy question about IF function

Status
Not open for further replies.

Markh51

Programmer
May 20, 2003
81
0
0
GB
How do I say, if a given form field value is equal to nothing then do something, else do something else.

This is what I have, so far:

if(document.step3[FieldName].value = ''){

DO SOMETHING...

}
else{

DO SOMETHING ELSE...

}

but I can't seem to format the IF statment properly.

So how do I write if the passed value in form step3 equal to nothing then do it.

Also how do I write NOT EQUALS.

p.s FieldName is passed to the script as a variable.

Cheers.
 
If you're testing the value of a variable you need to use the '=' twice. So your first line would need to be:

if(document.step3[FieldName].value == ''.

A single '=' is only used when assigning a value to a variable.

The path to freedom is seldom trodden by the multitude.
 
Your second question.. how do I write "not "qual"...

if(a != B){ // != is not equal
do something;
}


or you could play with this as well


if(!(a = B)){ // if a = B is not true
do something;
}

hope this helps you out
 
oops sorry... missed an = above

if(!(a == B)){ // if a = B is not true
do something;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top