Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hitting the enter on the keyBoard should default to "YES" button on the html/jsp page

 
trupti nigam
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can focus the button right away

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

Eric
 
trupti nigam
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so it would be like I believe:

<body onload="document.forms[0].yes.focus()">
 
trupti nigam
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
trupti nigam
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello all,

I got the answer to my question.

Thanks to all who all answered to my question immediately.

Thanks,
Trupti
 
trupti nigam
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic