tags:

views:

33

answers:

4

i have statement like this

var a = $("#txt1").val().trim()

how should check if 'a' is not empty

A: 
if (a !== null) {
    /* Do stuff */
}
Olly Hodgson
A: 

this should do

if(a != '') {
  // alert(a);
}
Wbdvlpr
+2  A: 

I think

if (a) { /* a is not empty */ }

should do the trick, perhaps unless a contains "false" (not sure of that) but I suppose you could do

if (a !== null && a.length != 0) { /* a is not empty */ }
roe
+1 for the second example. It's more robust and will work even with "false" in the field.
S Pangborn
A: 
if ( a !== "" ) { }
Locksfree