Reputation: 810
I am trying to if the value of an input box is blank or not by doing the below:
var id = $(this).attr('id').substr(3);
var lengthname = $("#input_name_"+id).val().length;
var lengthrss = $("#input_rss_"+id).val().length;
if (lengthrss!=0 || lengthname!=0)
{
// do something
}
else
{
alert('Values cannot be blank');
}
For some reason it is not doing the OR however if the user enters both values as blanks then the alert comes up??
Upvotes: 0
Views: 6678
Reputation: 57651
What you are looking for is an AND operation, not OR. The valid case is when both lengths are non-zero:
if (lengthrss!=0 && lengthname!=0)
{
// do something
}
Alternatively:
if (lengthrss==0 || lengthname==0)
{
alert('Values cannot be blank');
}
For reference: De Morgan's laws
Upvotes: 3