Want to add alert if searchTerm length ==0

<script type="text/javascript">


    $(function () {
        $("#searchTerm").autocomplete({
            //appendTo:"#abc",
            // position: { my : "right top", at: "right bottom" },
            source: "home/search",
            minLength: 1,

            autoFocus: true,
            select: function (event, ui) {
                if (ui.item) {
                    $("#searchTerm").val(ui.item.value);
                    $("form").submit();
                }
                else { alert("abc")}
            }

        });
    });
</script>

I tried several things but somehow i m not able to crack this simple thing. Thanks in advance

Answers


How about:

if($.trim($("#searchTerm").val()).length === 0) {
    alert("empty");
}

If the .value is a string then..

if (ui.item.value.length == 0)

Need Your Help

Looping and a boolean array?

java arrays loops random

I'm in my first Java programming class ever, and I am currently attempting to write up a user-made method that will loop through a boolean array, give me a random number, check if the array says the

Check to see if string is an integer (includes negative numbers) PHP

php regex integer isinteger

The function below checks if a string is an integer meaning it should only contain digits. But it does not check if number is negative (negative numbers should return true as well since they are

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.