tags:

views:

1650

answers:

4

I have the following code:

var inp = $("#txt");

if(inp.val() != "")
// do something

Is there any other way to check for empty textbox using the variable 'inp'

+2  A: 
if ( $("#txt").val().length > 0 )
{
  // do something
}

Your method fails when there is more than 1 space character inside the textbox.

rahul
+2  A: 
if (inp.val().length > 0) {
    // do something
}

if you want anything more complicated, consider regex or use the validation plugin which takes care of this for you

wiifm
A: 
var inp = $("input:text");

this should give you all textboxes

Natrium
A: 

how do I check if a field has a string value tht contains letters 'abc' containing in it using Jquery ??

srao