how to use "Pressing Enter Key" to activate an action of a button

I have a password input component (id=password) and a login button (id = bt_login). what I want is when users press "Enter Key", the action for login button is activated.

I tried this, if (event.keyCode == 13) {this.form1.bt_login.click();}

, but it does not work.

What should I do?

Thanks in advance,

[333 byte] By [field] at [2007-11-26 7:36:54]
# 1

I tried something similar to http://blogs.sun.com/roller/page/divas?entry=turning_an_input_component_into

I created a page with a Password Field component and a Button component.

Using Page Navigation, I created a link from the Button to Page2 and named it "go".

Back in the Visual Designer, I right-clicked in the Password Field and chose Auto-Submit on Change.

I double-clicked the button (which had an id of goButton) and changed its code as follows:

public String goButton_action() {

// TODO: Process the button click action. Return value is a navigation

// case name where null will return to the same page.

log("go button");

return "go";

}

That way I could tell if the action method was executed.

Then I went back to the Visual Designer and double-clicked the Password Field component. The IDE created a process value change method and displayed the method in the source editor. I changed it as follows:

public void passwordField1_processValueChange(ValueChangeEvent event) {

Application application = getApplication();

NavigationHandler navigator = application.getNavigationHandler();

FacesContext facesContext = getFacesContext();

String result = goButton_action();

try {

navigator.handleNavigation(facesContext, null, result);

} catch (Exception e) {

log("can't navigate to " + (String) result);

}

}

I clicked the Servers window header to display the window, right-clicked Deployment Server and chose View Server Log.

I ran the app. I typed something in the Password Field and pressed Enter. I looked at the log and saw "go button".

Hope this helps,

Chris

jetsons at 2007-7-6 19:37:39 > top of Java-index,Development Tools,Java Tools...
# 2
Thanks Chris,It works perfectly. Really appreciate your help!
field at 2007-7-6 19:37:39 > top of Java-index,Development Tools,Java Tools...