Using the Enter key to click a button in Lotus Notes

Instead of using your mouse to click a button or tabbing to a button and hitting the space bar, this JavaScript code from member Peter Smith will allow you to hit Enter to click a button in Lotus Notes, just like you can on a Web page.


Rather than using a mouse to click a button, or tabbing to the button and hitting the space bar, you can make Lotus Notes more like the Web by just hitting "Enter" to click the button. This is useful in things like search forms.

All client JavaScript events

YourSearchField onFocus
useClick = window.setInterval("runSearch()",100);
Form onLoad
useClick = window.setInterval("runSearch()",100); 

YourSearchField onBlur

The button has an HTML Name/ID of Search

Form JS Header
var newline = String.fromCharCode(10);
var useClick;
var sString;
var t_sString;

function runSearch() {
  sString = document.forms[0].Query.value;
   if (sString.indexOf(newline)>=0)    {
      t_sString = replace(sString, '\n', '');
      document.forms[0].Query.value = t_sString;

function replace(str, from, to) {
           var i = str.indexOf(from);
           if (!from || !str || i == -1) return str;
           var newstr = str.substring(0, i) + to;
           if (i+from.length < str.length)
           newstr += replace(str.substring
           return newstr;


This tip is exactly what I was looking for, but it doesn't seem to work for me. Is there any way you can help me?
—Serge M.


I just tested this by copying and pasting the code into a form and it worked fine, so I think it's one of the following issues:

  1. The user is using an old copy -- e.g., before you amended it. They should use what is currently there, specifically, check the line: t_sString = replace(sString, '\n', '')

  2. They don't have JavaScript enabled in their Lotus Notes client, or have an earlier release. It wasn't tested on R5.

  3. They haven't replaced the relevant parts of the code. For example, the field in the example is called "Query," whereas their search field might be called something different. Likewise, the HTML name for the button in the example is called "Search." Theirs may be named something different or not named at all.

—Peter Smith, tip author


The tip was amended on June 18, 2006. It is reflected in the code above.
—Matt Gervais, Assistant Editor


This is a nice tip, but it is important to mention that the rich-text field used as a search query must have: "enable multiple lines" on the control tab. If it is not, there won'tbe newlines characters in the field, and the JavaScript won't fire.
—Gregory E.

Do you have comments on this tip? Let us know.

This tip was submitted to the tip library by member Peter Smith Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

Dig Deeper on JavaScript for Lotus Notes Domino



  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...

  • HTML cheat sheet

    This is a really cool cheat sheet if you're looking to learn more about HTML. You'll find just about everything you every wanted ...

  • Carol Woodbury: Security

    Carol Woodbury