Whing Dela Cruz
asked on
Javascript the "if condition with Or"
Hi experts, I want to put "Or" in the if condition which codes are something like this,
If (result = 0 or Nan) //Either of the two
{
alert("Something wrong!")
}
If (result = 0 or Nan) //Either of the two
{
alert("Something wrong!")
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
As instructed by the system, I added [] for all "i" in the codes.. Thank you
ASKER
Hi hielo, Sorry for miss leading my question. The solution you have given to me is already correct, the only problem is my implementation of the codes. Thank you so much!
ASKER
Thank you much!
ASKER
If you can give me bonus about this question I need to put some "exit" here, after the alert. What I need is to stop the transaction if there something wrong on it. I tried to use break; but it doesn't work. Thank you!
if( isNaN(result) || result===0 )
{
alert( "Something is wrong" );
}
if( isNaN(result) || result===0 )
{
alert( "Something is wrong" );
}
>> for(var [i =0; s < tdXFirstCell.length; [i++)
Get rid of the bracket to the left of both i variables.
Your test condition on the loop uses an "s". You probably meant to use an i. It should be:
for(var i =0; i < tdXFirstCell.length; i++)
>> result = tdXFirstCell[[ i ].lastChild.value;
You have one left bracket too many to the left of the i. It should be:
result = tdXFirstCell[ i ].lastChild.value;
Just typereturn;
after the alert.
ASKER
Thank you hielo, everything is noted! Thanks for your for help it helps me a lot pursuing my project.
ASKER
<script>
function CheckSalesTable()
{
var result = "0";
var z = 1;
var tbl = document.getElementById('S
var tdXFirstCell = tbl.querySelectorAll('tr td:nth-child(5)');
for(var [i =0; s < tdXFirstCell.length; [i++)
{
result = tdXFirstCell[[i].lastChild
if (( isNaN(result) || result==0 ))
{
alert("Your order number " + z + " is wrong in quantity");
}
else
{
alert("b88")
}
result = 0;
z = (z + 1);
}
}
</script>