• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"enter key" button focus ?

 
Javoso Torso
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
sreenath reddy
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sreenath.
I tried it.
cancel is keeping the focus,
don't know why...
 
sreenath reddy
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic