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!

Debugging a simple IF statement

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am struggling with what appears to be a problem with an IF statement in my javascript program. I have the statement:

if((insal<10000) || (inpayback!=paytwo) || (inpayback!=payone))
{
//display error message
alert(&quot;Invalid entry. Please adjust details&quot;);
}
else
{...}

If I run the pogram as shown above, the alert mesage always appears when the event if captured. If however I removed the last of the three conditions (|| (inpayback!=payone)))the IF statement functions as it should.

Does anyone have a suggestion???

PS If you reply saying the my brackets are wrong, please explain why!?!
 
As a debug measure, have you tried outputting the values of all the variables before the IF loop so that you know it the loop is working correctly. Maybe the problem is somewhere else. Try this and examine the values for a number of different cases and make sure that what the IF loop does corresponds with the values:

alert(&quot;insal: &quot; + insal + &quot;\ninpayback: &quot; + inpayback + &quot;\npayone: &quot; + payone + &quot;\npaytwo: &quot; + paytwo);
if((insal<10000) || (inpayback!=paytwo) || (inpayback!=payone))
{
//display error message
alert(&quot;Invalid entry. Please adjust details&quot;);
}
else
{...}



Mise Le Meas,

Mighty :)
 
Tried the above solution and all the vars displayed the correct values. Nice try though. All suggestions now welcome!!!
 
Perhaps the booleans are not evaluating correctly. Try checking each boolean expression individually to see how they evaluate. For example:

var bool1,bool2,bool3;
bool1 = insal<10000;
bool2 = inpayback!=paytwo;
bool3 = inpayback!=payone;
alert(&quot;bool1: &quot; + bool1 + &quot;\nbool2: &quot; + bool2 + &quot;\nbool3: &quot; + bool3);

Also, I assume that the else clause has actual working code and not the ... in it. If not, that would be a problem.
 
Just a quick though, but are you getting the value of &quot;insal&quot; from a form? If you are and you haven't converted it to a number that could be the problem...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top