Marc Jonkers
Marc Jonkers

Reputation: 506

set focus on a button

I have a simple xpage with 2 inputText field (username and password) and a button.

The idea is that when hitting the "return" or "enter" key , that the onclick event of the button will be activated. I guess this is normally done with an auto onfocus, but can't find a way to let this work.

Upvotes: 2

Views: 113

Answers (2)

Sam Sirry
Sam Sirry

Reputation: 762

From the Button's "All Properties" tab, set type to submit,

as shown in this screenshot.

Upvotes: 0

shillem
shillem

Reputation: 1260

I think best is to define a small function from a js library you load in each page you need this

function fireButton(e, buttonId) {
    if (typeof e == "undefined" && window.event) {
        e = window.event;
    }

    if (e.keyCode == dojo.keys.ENTER) {
        dojo.byId(buttonId).click();
        e.preventDefault();
    }
}

Then in the onkeydown attribute you can call it:

<xp:inputText onkeydown="fireButton(event, '#{id:buttonId}')"

Upvotes: 1

Related Questions