Coding Tips: February 2008 Archives

In a ProStores store, a blank keyword search will return "All" products — If you have a large catalog, this is never a good thing. Expecting your users to view 2000 items 25 items at a time is just silly. Here is a quick, easy way to completely remove the possibility of a blank keyword search in your ProStores store.

In Page Template Manager, locate the opening of the default keyword search form found in the Header template source code. It should look something like this:


<form method="post" action="$storeVersion.searchResults"></form>

There is a DOM event called "onSubmit". Using this event, we can easily add a test to the form that will keep the form from being submitted if the keyword input is empty. Example:

onSubmit="if(document.searchForm.keyword.value == '') return false;"

Once you correctly add the event to the form element it should look like this:


<form method="post" action="$storeVersion.searchResults" onSubmit="if(document.searchForm.keyword.value == '') return false;"></form>

Now, with no complicated form validation or any other scripting, your keyword search form cannot be submitted unless the user enters a keyword. That makes sense, right? You're welcome.

About this Archive

This page is an archive of blog entries in the Coding Tips category from February 2008.

Coding Tips: November 2007 is the previous archive.

Coding Tips: April 2008 is the next archive.

Find recent content on the main index or look in the archives to find all content.