Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Struts and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark ""enter key" button focus ?" Watch ""enter key" button focus ?" New topic
Author

"enter key" button focus ?

Javoso Torso
Ranch Hand

Joined: Aug 15, 2003
Posts: 88
Hello
I have following prob:
a form with three buttons

a submit (normal html-button)
a cancel (struts html:cancel button)
and a reset (struts html:reset button)

since I need javascript to run before submition
and after the result of the javascript function deciding if submiting or not I used a submit html-button (I cannot stop the struts html:submit button from submitting even if a put a javascript onClick after the javascript function comes the submition (is there a way to stop it?)).
For the other two buttons the struts html tags.

Now if the user press enter (regardless where the focus is in the form) the cancel action is being activated (the form cancelled)

if I use javascript to put the focus on submit, as soon as the user click on a text field (or any other form component) the "button group focus" moves to the cancel button!
(regardless where was the focus is in the form)

How can I get the "enter key focus" staying on submit?


I already tried the struts <html:form ... focus="submitButton"> and it works at page-load-time BUT as soon as the user click on a text field (or any other form component) the "button group focus" moves to the cancel button ! ! !

Is there a kind of "enter key" focus?
Thanks!


I hate 'trial and error'<br />and I am doing it all the time
sreenath reddy
Ranch Hand

Joined: Sep 21, 2003
Posts: 415
Hi
U can hp fot <html:button> instead of <html:submit> as this submits irrespective of ur javascript return false............and if u use <html:button> u need to manually submit the page
Javoso Torso
Ranch Hand

Joined: Aug 15, 2003
Posts: 88
Thanks Sreenath.
I tried it.
cancel is keeping the focus,
don't know why...
sreenath reddy
Ranch Hand

Joined: Sep 21, 2003
Posts: 415
Hi
There is onKeyPress attribute for body tag.u can associate this with a javascript function where u can handle the event and there u can catch the enter key event and do appropriate things

for example on keyPress u call some javascript function called
function a()
{
if (window.event.keyCode == 13)
submit();
}
Thus u can submit when the user presses Enter button
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "enter key" button focus ?