Forums Register Login
hitting the enter on the keyBoard should default to "YES" button on the html/jsp page
Hello all,

I have a JSP page,on which there are two buttons. "YES" and "NO". when the user enters the valid data and hits the enter on the keyBoard, it should default to the "YES" button. Does any one knows how to achieve this?

Thanks in advance.
you can focus the button right away

<body onload="document.formName.yesName.focus()">

I am using struts HTML:FORM tag like below:

<html:form action="/someAction" method="post" style="display:inline"> <br>

<td width="12%" align="right" >
<html:image property="yes" src="img/btn_yes.gif" alt="Yes, ignore this transaction" title="Yes, ignore this transaction" />

so it would be like I believe:

<body onload="document.forms[0].yes.focus()">
When i hit the "enter" button on the keyboard ,on the IE i could see the
windows image moving which indicates that something is happening in the background.But after few seconds it stops and nothing happens.
I tried to debug it , using the debugger but I am not able to find the problem. after the execution of particular thread it says local varibales not avialable and the thread stops.

hello all,

I got the answer to my question.

Thanks to all who all answered to my question immediately.

I am using struts. So I have JSP ,an action form and and an action class.

The problem is that we have a common logic developed for all the forms in the project. We have three cases like default,buttonYes and buttonNo.And when the user hits the yes ,he is directed to that case. Due to this the enter key pressed is not getting recognised and when the user presses enters it goes to default case.

I tried the windows.document.onKeyPress(),but hitting "enter" key is not getting recognised .

can some one plese suggest something.


Make the Yes button have "submit" semantics. A simple example:

This will cause it to be activiated, and its enclosing form submitted, when the Enter key is pressed within a form element.

Yes, I know you are using Struts, but that doesn't mean that you have to use Struts tags to create your buttons. Back away from the Struts crutch for just a moment and figure out what's really happening on your page.
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards

All times above are in ranch (not your local) time.
The current ranch time is
Oct 21, 2017 13:31:56.