Home » Jquery » Jquery Fix for WordPress Empty Search issue

Jquery fix for preventing wordpress empty search issue. I found a decent/easy jquery workaround on preventing submit if the field is empty:

/**
 * Stop empty searches
 *
 * @author Thomas Scholz http://toscho.de
 * @param  $ jQuery object
 * @return bool|object
 */
(function( $ ) {
   $.fn.preventEmptySubmit = function( options ) {
       var settings = {
           inputselector: "#s",
           msg          : "Don’t waste your time with an empty search!"
       };
       if ( options ) {
           $.extend( settings, options );
       };
       this.submit( function() {
           var s = $( this ).find( settings.inputselector );
           if ( ! s.val() ) {
               alert( settings.msg );
               s.focus();
               return false;
           }
           return true;
       });
       return this;
   };
})( jQuery );

And onload:

jQuery( "#searchform" ).preventEmptySubmit();
Leave a comment

0 Comments.

Leave a Reply


[ Ctrl + Enter ]

*

Wordpress Freelancer, Joomla Freelancer Web designer Mumbai india, Wordpress web developer India, Joomla Web developer india, Outsourcing web project india mumbai

By Santosh Kori Published: October 10, 2012 Professional Freelance Website developer 5 stars based on 65 reviews Total time: 24 hour 00 min Wordpress Joomla XHTML CSS jQuery HTML5 eCommerce CSS3 ☞ Offers low cost freelance web designing, asp php asp.net web development services from Mumbai India. Freelance web designer & developer Mumbai India.

I AM NOT AVAILABLE FOR WEB DESIGN & DEVELOPMENT PROJECTS