Skip to main content


Making the “Enter” key submit searches in SharePoint

While the default SharePoint search box works well for most browsers, there’s a surprising inconsistency with Firefox: Hitting “enter” won’t submit your search.
The reason is that Mozilla browsers use a different event model which SharePoint’s “search.js” file doesn’t fully account for. Specifically, when the enter key is pressed, this code is run:
try {if(null != event) event.returnValue = false;} catch (err) {}

Internet Explorer, Opera, and Webkit-based browsers (Safari, Chrome, etc.) support the global event object, but Firefox does not. Thus, the try object supresses the error and nothing happens.
To fix it, we can write our own event handler for any search box. A nice bonus is that this can be adapted to work with any search page, including custom ones built on web parts.
First, add this Javascript to your masterpage HEAD, a Javascript include file, or a Content Editor Web Part. There are two variables you’ll need to change:

  • searchUrl – The location of your search page.
  • searchBoxId – The ID of your search textbox.
functionsearchKeyDown(event) {


 var searchUrl = '/Pages/Search.aspx';


 var searchBoxId = 'searchElement';



event = window.event;

 varkc = event.which ? event.which : event.keyCode;

if (kc == 13)
setTimeout(“location.href = ‘” + searchUrl + “?k=’ + escape(document.getElementById(‘” + searchBoxId + “‘).value)”, 15);
Second, find your search box’s definition and add the following onkeydown attribute:


Hitting enter should now complete your searches in all browsers.

Thoughts on “Making the “Enter” key submit searches in SharePoint”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

PointBridge Blogs

More from this Author

Follow Us