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 SearchDomino.com member Peter Smith will allow you to hit Enter to click a button in Lotus Notes, just like you can on a Web page.

VIEW MEMBER FEEDACK TO THIS TIP

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);
OR
Form onLoad
useClick = window.setInterval("runSearch()",100); 

YourSearchField onBlur
window.clearInterval(useClick);

YourSearchButton
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;
      document.forms[0].elements['Search'].click();
    }
}

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
(i+from.length,str.length),from,to);
           return newstr;
}

MEMBER FEEDBACK TO THIS TIP

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, SearchDomino.com 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 SearchDomino.com 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.

This was last published in July 2006

Dig Deeper on JavaScript for Lotus Notes Domino

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close