In which cases do an input field value equals '', null or undefined.
I’m trying to check empty fields
if($('#cur').val() == 'undefined' || $('#cur').val() == '' || $('#cur').val() == 'null'){
alert('Blank');
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The value of an
inputelement will always be a string. You can safely just compare to the empty string:You are currently checking for the string literals “undefined” and “null”. That would only be the case if the value of the
inputwas actually the string “undefined” or “null”. For example:It may be worth noting that if the
inputcontains blank spaces but nothing else, and you want to count that as empty, the above will not suffice. You can use the jQuerytrimfunction to remove leading/trailing white space from a string: