0

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??

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

goshh...u r right....I feel dumb...i guess i can't think at 1 a.m. in the morning ;-)
Yes, trivial mistakes are usually a reminder that it is bed time ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.