0

Possible Duplicate:
Check if textbox has empty value

How do I check if an input value is blank?

I am currently doing:

if($(#inputid).val()=="") {
    alert("its blank");
}
Community
  • 1
  • 1
codeguy
  • 51
  • 1
  • 1
  • 6

3 Answers3

4

Try quoting your selector string:

if ($("#inputid").val() == "") {
    ...

You might want to trim to stop whitespace from counting:

if ($.trim($("#inputid").val()) == "") {
    ...
karim79
  • 339,989
  • 67
  • 413
  • 406
2

Try:

if( !$.trim($("#inputid").val()).length ) {
  alert("blank");
}
Naveed
  • 41,517
  • 32
  • 98
  • 131
1

You can just do:

if (!$('#id').val()) { 
    //is blank 
}
elclanrs
  • 92,861
  • 21
  • 134
  • 171