This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes hitting the enter on the keyBoard should default to Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "hitting the enter on the keyBoard should default to "YES" button on the html/jsp page" Watch "hitting the enter on the keyBoard should default to "YES" button on the html/jsp page" New topic
Author

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

trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
you can focus the button right away

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

Eric
trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
so it would be like I believe:

<body onload="document.forms[0].yes.focus()">
trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
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

Joined: Jun 21, 2001
Posts: 613
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

Joined: Jun 21, 2001
Posts: 613
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

Joined: Jan 10, 2002
Posts: 60822
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hitting the enter on the keyBoard should default to "YES" button on the html/jsp page
 
Similar Threads
hitting the enter on the keyBoard should default to "YES" button on the html/jsp page
How to set Default button in Swing
Two Submit buttons in JSP Page
How to set default image button
Form submit