Prohibit Enter and Click Button

Mindwatering Incorporated

Author: Tripp W Black

Created: 04/26/2022 at 01:00 PM

 

Category:
Notes Developer Tips

Task:
When a person click's Enter within a text field, click the button next to the field.

Scenario:
Let us assume the field is named KT_Name (with ID and Name props populated)
Let us assume the button is named Filter (with ID and Name props populated)

Note:
Skip to option 2 for Notes client.


Option 1:
// add listener for KT_Name field to click Filter button
var input = document.getElementById("KT_Name");
input.addEventListener("keypress", function(event) {
if (event.key === "Enter") {
event.preventDefault();
document.getElementById("Filter").click();
}
});


Option 2:
Add to the onKeyDown field event:
... onKeyDown="doBtnClick" ...

function doBtnClick() {
if (event.keyCode === 13) {
event.preventDefault();
document.getElementById("alertBtn").click();
}
}












previous page