Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

"enter key" button focus ?

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!

 
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I wish to win the lottery. I wish for a lovely piece of pie. And I wish for a tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic