OpenNTF.org - Using the Enter key to click a
My Links (Not logged in)
Code Bin Search
 
Hosted by Prominic.NET
Rate This Code
5 - brilliant stuff
4 - very nice
3 - average
2 - needs work
1 - bad
   OpenNTF Code Bin
About This Code
Brief Description:
Using the Enter key to click a button in Lotus Notes 
Rating:
Rating: 2 , Number of votes: 1 
Contributor:
Peter Smith 
Category:
Javascript 
Type:
Example Code 
Document Release:
1.0 
Notes Version:
R6.x, R7.x 
Last Modified:
19 Jul 2006 
OpenNTF Disclaimer

All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.

Code / Description
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.


It uses a JS timer in the Notes Client to allow users to just hit Enter instead of clicking a button or using Space (i.e. in a search form). The timing in milliseconds can be decreased, but at a cost to the processing % used by the Client

Usage / Example
All are Client Javascript

1. YourSearchField onFocus event OR YourSearchForm onLoad event
// Check every 1/10 of a second
useClick = window.setInterval("runSearch()",100);

2. YourSearchField onBlur event OR YourSearchForm onUnload event
window.clearInterval(useClick);

3. YourButton
The button has an HTML Name/ID of "Button"

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

function runSearch() {
sString = document.forms[0].YourSearchField.value;
if (sString.indexOf(newline)>=0) {
t_sString = replace(sString, '\n', '');
document.forms[0].YourSearchField.value = t_sString;
document.forms[0].elements['Button'].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;
}
 Comments
Posted by Volker Mannherz on 07/20/2006 03:06:46 AMBug with onLoad event
Excuse me, but this tip is not working on my configuration (Win XP german keyboard layout / LN 6.5.3 EN)
if i use onFocus event of the search-field -> nothing happens
if i use onLoad event of the form -> i get about 20 msgboxes from my Search-Button click event and 131 new LN windows from msgboxes with error: "Too many recursive formula evaluations" (before Notes crashes)
Any Idea ?
Volker
 Add your comment!