avoiding empty submissions

I use Atomz search to allow users to search my site and the weekly report always has the same top query. It is (drum roll please):

blank query

I have no idea why someone would search for nothing, because you get just that as a result, but search for nothing they did.

I decided to put a stop to it. In the header I added a Javascript function that checks the value of the search field and if blank, pops up a message asking the user to please enter a search phrase. Here’s the code to do that.

<script type="text/javascript" language="Javascript">
//<!--
function validateSearch()
{
    if ( document.search.sp_q.value == "" )
    if ( document.search.sp_q.value.match( /^\s*$/ ) != null )
    {
        alert( "Please enter a search phrase" );
        return false;
    }

    return true;
}
//-->
</script>

The Javascript method is executed when the user hits the search button by adding the bold text.

<form name="search" method="get" action="http://search.atomz.com/search/"
 onSubmit="return validateSearch();">
<input type=text size=30 name="sp_q"><br>
<input type=submit value="Search this site">
</form>

Blank queries still show up occasionally, but they’re probably from users who have Javascript disabled. An even better solution would be for the server to make sure the search isn’t blank too, but since I don’t have access to the server-side code, this is the best I can do.







Number of readers
- home
comics
news links
other links

about me
blog archives
docs
entertainment
experiences
funny lists
humor
intellectual
interests
metafilter
music
opinions
photos
web designs
tools
software
webmaster help

Sign up
Enter your email address to be notified of new posts



Search blog archives

Calendar
July 2004
S M T W T F S
« Jun   Aug »
 123
45678910
11121314151617
18192021222324
25262728293031







Random quote
(View all quotes)
"Music is adrenaline printed in ink. -- Taylor Rodgers"










(?) Choose theme:  X X X X X X