apamphilon

Prevent empty search

$('.search-form').submit(function(e) { // run the submit function, pin an event to it
    var s = $( this ).find(".search-field").val($.trim($( this ).find(".search-field").val())); // find the .search-field, which is the search input id and trim any spaces from the start and end
    if (!s.val()) { // if search-field has no value, proceed
        e.preventDefault(); // prevent the default submission
        $('.search-field').focus(); // focus on the search input
    }
}); 

Comments: