Virtual Forms and Return key
Hi Everybody,
I am relatively new to JSP/JSF and started writing my very first project.
At the moment I am trying to solve a, hopefully, relatively simple problem:
I have a GUI with several text fields and a 'search' button for each text field. The idea is to let the user type a string and/or a number and then use the search button to get the information from a underlying database. The problem arise if the user hits the return button. Should that be the case, the browser seems to use the first button in the page or the last one used.
Is there a way to control which action the return key triggers?
Many thanks
Regards
Luca
[679 byte] By [
SPITUa] at [2007-11-26 13:36:44]

# 1
http://onesearch.sun.com/search/onesearch/index.jsp?qt=enter+key&col=develop er-forums&subCat=siteforumid%3Ajava881&site=dev&dftab=siteforumid%3A java881&chooseCat=javaall&cs=false&rt=true
The first four results are all pertinent. If you have a look further down you'll even find one from craigmcc circa 2004. And of course Jetsons has already helped out someone with this problem.
Seems like folks have had sucess with a) arranging button as first on page or b) using javascript to intercept the enter key.
# 3
if (event.keyCode == 13) {alert("intercept");document.getElementById("form1:button1").click();}
Note camelCase on keyCode.
I'm not sure how this.form1.buttonxxx.click() works so I used getElementById()
You probably need to stop the enter key feeding through to the browser. You'll have to research how.
# 4
I have used your version, slightly modified, and it worked. I added a 'return false' at the end to try to stop the feed through of the enter key.
if (event.keyCode == 13) {alert("intercept");document.getElementById("form1:button1").click(); return false}
Any idea why using a direct id for the button does not work? It would be nice to understand that behavoiur.
Many thanks
Regards
Luca