[Logo]
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.
Trupti
you can focus the button right away

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

Eric
I am using struts HTML:FORM tag like below:

<body>
<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" />
</td>

Thanks,
Trupti
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.

Thanks,
trupti
hello all,

I got the answer to my question.

Thanks to all who all answered to my question immediately.

Thanks,
Trupti
Hello,
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.

Thanks,

Trupti
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


This thread has been viewed 847 times.

All times above are in ranch (not your local) time.
The current ranch time is
Dec 18, 2017 13:46:21.